/**
 * Created by Eric on 2017/8/17.
 * Depending on the jquery-1.12.4.min.js.
 * Depending on the common.js.
 * Depending on the style.min.css.
 * To cite this document, always state the source as shown above.
 * -------------------------------
 * Module:客户档案
 * -------------------------------
 */
$(function () {
  file.renderData(file.enterprise);
  file.renderData(file.personal);
  file.renderData(file.other);
  file.verifier('.file-verifier');//开启验证功能
  /*-----arttemplate注册过滤器--S--*/
  //时间格式
  template.defaults.imports.dateFormat = function (time) {
    /*Arg Guide
     @ time 时间辍
     */
    if (time == null) {
      return '';
    }
    var date = new Date(time);
    return date.getFullYear() + '-' + (date.getMonth() + 1) + '-'
        + date.getDate();
  };
  //分转万元
  template.defaults.imports.changeMoneyUnit = function (money) {
    /*Arg Guide
     @ money 金额(分)
     @ return 金额(万元)
     */
    var money = money - 0;
    var unit = 6;
    if (typeof money !== 'number') {
      return false;
    }
    return (money / Math.pow(10, unit)).toFixed(2);//保留两位有效数字
  };
  /*-----arttemplate注册过滤器--E--*/

  /*-----添加客户功能--S--*/
  //添加客户(企业)
  $('#file').on('click', '#addCustomerEnterprise', function () {
    var $modal = $('#' + 'modal_addEnterprise');//获取对应模态框
    $modal.modal({
      closable: false,
      transition: 'fade',
      onDeny: function () {
        $('#query_enterprise').trigger('click');//ajax刷新页面
      },
      onHidden: function () {
        $('#query_enterprise').trigger('click');//ajax刷新页面
      }
    }).modal('show');//弹窗
    $modal.find('#content').empty().html(template('content_enterprise', ''));
    file.stepResponseEnterprise('modal_addEnterprise');//步骤事件初始化
    file.verifier('#modal_addEnterprise .file-verifier');//开启验证功能
    //ui功能开启
    $('.ui.radio.checkbox').checkbox();
    $('.ui.dropdown').dropdown();
    tagFunction('#modal_addEnterprise .cus-tags-box');
    //添加联系人功能初始化
    contactFunction('#modal_addEnterprise #addContactbox', true);
    //添加抬头功能初始化
    invoiceFunction('#modal_addEnterprise #addInvoicebox', true);
    //上传pdf功能
    file.uploadFilePdf('#modal_addEnterprise #addInvoicebox',
        '#uploadProof_label', '#uploadProof_form');//一般纳税人证明
    //城市
    $modal.find("#city").citypicker();
    //单个日期
    wzERP.Common.singleDate('.single-date');
    //起始日期
    wzERP.Common.inlineDate('#' + 'modal_addEnterprise .rangestart',
        '#' + 'modal_addEnterprise .rangeend');
  })

  //添加客户(个人)
  $('#file').on('click', '#addCustomerPersonal', function () {
    var $modal = $('#' + 'modal_addPersonal');//获取对应模态框
    $modal.modal({
      closable: false,
      transition: 'fade',
      onDeny: function () {
        $('#query_personal').trigger('click');//ajax刷新页面
      },
      onHidden: function () {
        $('#query_personal').trigger('click');//ajax刷新页面
      }
    }).modal('show');//弹窗
    $modal.find('#content').empty().html(template('content_personal', ''));
    file.stepResponsePersonal('modal_addPersonal');//步骤事件初始化
    file.verifier('#modal_addPersonal .file-verifier');//开启验证功能
    //tab切换功能开启
    $('.tabular.menu .item').tab();
    //ui功能开启
    $('.ui.radio.checkbox').checkbox();
    $('.ui.dropdown').dropdown();
    //添加联系人功能初始化
    contactFunction('#modal_addPersonal #addContactbox', true);
    //添加抬头功能初始化
    invoiceFunction('#modal_addPersonal #addInvoicebox', true);
    //上传pdf功能
    file.uploadFilePdf('#modal_addPersonal #addInvoicebox',
        '#uploadProof_label', '#uploadProof_form');//一般纳税人证明
    //城市
    $modal.find("#city").citypicker();
    //单个日期
    wzERP.Common.singleDate('.single-date');
    //起始日期
    wzERP.Common.inlineDate('#' + 'modal_addPersonal .rangestart',
        '#' + 'modal_addPersonal .rangeend');
  })

  //添加客户(其它组织)
  $('#file').on('click', '#addCustomerOther', function () {
    var $modal = $('#' + 'modal_addOther');//获取对应模态框
    $modal.modal({
      closable: false,
      transition: 'fade',
      onDeny: function () {
        $('#query_other').trigger('click');//ajax刷新页面
      },
      onHidden: function () {
        $('#query_other').trigger('click');//ajax刷新页面
      }
    }).modal('show');//弹窗
    $modal.find('#content').empty().html(template('content_other', ''));
    file.stepResponseOther('modal_addOther');//步骤事件初始化
    file.verifier('#modal_addOther .file-verifier');//开启验证功能
    //tab切换功能开启
    $('.tabular.menu .item').tab();
    //ui功能开启
    $('.ui.radio.checkbox').checkbox();
    $('.ui.dropdown').dropdown();
    //添加联系人功能初始化
    contactFunction('#modal_addOther #addContactbox', true);
    //添加抬头功能初始化
    invoiceFunction('#modal_addOther #addInvoicebox', true);
    //上传pdf功能
    file.uploadFilePdf('#modal_addOther #addInvoicebox', '#uploadProof_label',
        '#uploadProof_form');//一般纳税人证明
    //城市
    $modal.find("#city").citypicker();
    //单个日期
    wzERP.Common.singleDate('.single-date');
    //起始日期
    wzERP.Common.inlineDate('#' + 'modal_addOther .rangestart',
        '#' + 'modal_addOther .rangeend');
  })
  /*-----添加客户功能--E--*/

  //查看客户
  $('#file').on('click', '.viewBtn', function () {
    var id = $(this).data('id');
    $('#cust').val(id);
    var type = $('#file >.tabular.menu').find('.item.active').data('type');
    var config = {}
    switch (type) {
      case 'enterprise':
        config = {
          modalBox: 'modal_addEnterprise_viewedit',
          tpl: {
            page0: 'modalTpl_addEnterprise_page0',//企业资料
            page1: 'modalTpl_addEnterprise_page1'//经营状况
          }
        };
        handleEnterprise();
        break;
      case 'personal':
        config = {
          modalBox: 'modal_addPersonal_viewedit',
          tpl: {
            page0: 'modalTpl_addPersonal_page0',//个体资料
          }
        };
        handlePersonal();
        break;
      case 'other':
        config = {
          modalBox: 'modal_addOther_viewedit',
          tpl: {
            page0: 'modalTpl_addOther_page0',//其它组织资料
          }
        };
        handleOther();
        break;
      default:
        return false;
    }
    ;
    //查看企业客户
    function handleEnterprise() {
      var renderData = {} //渲染的数据
      //初始化事件
      var $modal = $('#' + config.modalBox);//获取对应模态框
      $modal.modal({
        closable: false,
        transition: 'fade'
      }).modal('show');//弹窗
      $modal.find('.ui.header .act-type').text('企业详情');
      $modal.find('.content > .tab-box').addClass('view-mode').removeClass(
          'edit-mode');//查看模式
      $modal.find('.actions').hide();//隐藏弹窗底部操作框
      $modal.find('.tabular.menu .item').tab();//tab切换开启
      $modal.find('.ui.tabular .item').eq(0).addClass('active').siblings(
          '.item').removeClass('active');
      $modal.find('.ui.tab').eq(0).addClass('active').siblings(
          '.tab').removeClass('active');//默认显示第一页
      $modal.find('.ui.tab.active').scrollTop(0);//滚动到顶部

      //联系和发票是否已渲染
      var hasRenderContact = false;
      var hasRenderInvoice = false;

      //tab导航点击加载事件
      $modal.on('click', '.ui.tabular.menu .item', function () {
        var pageIndex = $(this).index(); //获取当前页的tab索引
        switch (pageIndex) {
          case 1:
            if (!hasRenderContact) {
              templateRenderPage1()
            }
            break;
          case 2:
            if (!hasRenderInvoice) {
              templateRenderPage2()
            }
            break;
          default:
            return false;
        }
        $modal.find('.ui.tab.active').scrollTop(0);//滚动到顶部
      })
      //渲染第一页
      $.post('/customer/findById', {id: id}, function (result) {
        if (result.code == 0) {
          renderData.enterpData = result.data;//企业资料渲染数据
          console.log(result);
          //获取客户标签
          $.get('/customer/erpCustomerLabel/findCusIdAll', {id: id},
              function (result) {
                if (result.code == 0) {
                  renderData.enterpData.custLabels = result.data;
                  //数据渲染
                  var tplBox = $modal.find('#modal_enterprise_data');
                  tplBox.empty().html(template(config.tpl.page0, renderData));
                  //解决在查看没法放大的bug
                  //图片
                  $modal.find('.cop-info-box .zoom-label').off('click').click(
                      function () {
                        var filePath = $(this).siblings(
                            'input[type="hidden"]').val();
                        file.openBigPic('#bigPicShowLayer', filePath);
                      })
                  //pdf
                  $modal.find('.enterprise-bk .zoom-label').off('click').click(
                      function () {
                        var filePath = $(this).siblings(
                            'input[type="hidden"]').val();
                        window.open(filePath);
                      })
                }
              })
        }
        else if (result.code == 9999) {
          layer.msg(result.msg, {time: 1000});
          wzERP.Common.TimeoutLogin();
          return false;
        }
        else {
          console.log('企业资料获取失败!');
        }
      })
      //渲染第二页
      function templateRenderPage1() {
        $.post('/customer/erpContactInformation/queryAll', {custId: id},
            function (result) {
              if (result.code == 0) {
                renderData.contact = result.data;//联系方式渲染数据
                if (renderData.contact == null || renderData.contact.length
                    == 0) {
                  renderData.contact = '';
                  var tplBox = $modal.find('#modal_contact_viewedit');
                  tplBox.empty();
                } else {
                  var contactId = renderData.contact.contactType; //获取联系人类型id
                  //获取数据词典联系人类型
                  //根据联系人类型id获取名
                  $.get(
                      '/finance/erpAccountReceivable/querydictionDetailListByCode?code=contactsType',
                      function (result) {
                        if (result.code == 0) {
                          var _data = result.data;
                          var contactObj = {}
                          _data.forEach(function (val) {
                            contactObj[val.dictionaryDetailKey] = val.name;
                          });
                          renderData.contact.forEach(function (val) {
                            val.contactTypeName = contactObj[val.contactType] //获取联系人类型名
                          });
                          //渲染页面
                          var tplBox = $modal.find('#modal_contact_viewedit');
                          tplBox.empty().html(
                              template('modalTpl_addEnterprise_page3',
                                  renderData));
                          //添加联系人功能初始化
                          contactFunction('#' + config.modalBox
                              + ' #modal_contact_viewedit');
                          $modal.find('.select-ui-box select').dropdown();
                          //解决在查看没法放大的bug
                          //图片
                          $modal.find('.cop-info-box .zoom-label').off(
                              'click').click(function () {
                            var filePath = $(this).siblings(
                                'input[type="hidden"]').val();
                            file.openBigPic('#bigPicShowLayer', filePath);
                          })
                          //pdf
                          $modal.find('.enterprise-bk .zoom-label').off(
                              'click').click(function () {
                            var filePath = $(this).siblings(
                                'input[type="hidden"]').val();
                            window.open(filePath);
                          })
                        }
                      });
                }
                hasRenderContact = true;//已渲染联系方式
              }
              else if (result.code == 9999) {
                layer.msg(result.msg, {time: 1000});
                wzERP.Common.TimeoutLogin();
                return false;
              }
            })
      }

      //渲染第三页
      function templateRenderPage2() {
        $.post('/customer/erpInvoiceHeaderManage/findAll', {custId: id},
            function (result) {
              if (result.code == 9999) {
                layer.msg(result.msg, {time: 1000});
                wzERP.Common.TimeoutLogin();
                return false;
              }
              renderData.invoice = result.data;//发票抬头渲染数据
              if (renderData.invoice == null || renderData.invoice.length
                  == 0) {
                renderData.invoice = ''
              }
              var tplBox = $modal.find('#modal_invoice_viewedit');
              tplBox.empty().html(
                  template('modalTpl_addEnterprise_page4', renderData));
              //解决在查看没法放大的bug
              //图片
              $modal.find('.cop-info-box .zoom-label').off('click').click(
                  function () {
                    var filePath = $(this).siblings(
                        'input[type="hidden"]').val();
                    file.openBigPic('#bigPicShowLayer', filePath);
                  })
              //pdf
              $modal.find('.enterprise-bk .zoom-label').off('click').click(
                  function () {
                    var filePath = $(this).siblings(
                        'input[type="hidden"]').val();
                    window.open(filePath);
                  })
              hasRenderInvoice = true;//已渲染发票抬头
            })
      }
    }

    //查看个体客户
    function handlePersonal() {
      var renderData = {} //渲染的数据
      //初始化事件
      var $modal = $('#' + config.modalBox);//获取对应模态框
      $modal.modal({
        closable: false,
        transition: 'fade'
      }).modal('show');//弹窗
      $modal.find('.ui.header .act-type').text('个体详情');
      $modal.find('.content > .tab-box').addClass('view-mode').removeClass(
          'edit-mode');//查看模式
      $modal.find('.actions').hide();//隐藏弹窗底部操作框
      $modal.find('.tabular.menu .item').tab();//tab切换开启
      $modal.find('.ui.tabular .item').eq(0).addClass('active').siblings(
          '.item').removeClass('active');
      $modal.find('.ui.tab').eq(0).addClass('active').siblings(
          '.tab').removeClass('active');//默认显示第一页

      //联系和发票是否已渲染
      var hasRenderContact = false;
      var hasRenderInvoice = false;

      //tab导航点击加载事件
      $modal.on('click', '.ui.tabular.menu .item', function () {
        var pageIndex = $(this).index(); //获取当前页的tab索引
        switch (pageIndex) {
          case 1:
            if (!hasRenderContact) {
              templateRenderPage1()
            }
            break;
          case 2:
            if (!hasRenderInvoice) {
              templateRenderPage2()
            }
            break;
          default:
            return false;
        }
      })
      //渲染第一页
      $.post('/customer/erpIndividualCustomer/findById', {id: id},
          function (result) {
            if (result.code == 0) {
              renderData.personalData = result.data;//企业资料渲染数据
              console.log('个体资料:', result);
              //数据渲染
              var tplBox = $modal.find('#modal_personal_data');
              tplBox.empty().html(template(config.tpl.page0, renderData));
              //解决在查看没法放大的bug
              //图片
              $modal.find('.cop-info-box .zoom-label').off('click').click(
                  function () {
                    var filePath = $(this).siblings(
                        'input[type="hidden"]').val();
                    file.openBigPic('#bigPicShowLayer', filePath);
                  })
              //pdf
              $modal.find('.enterprise-bk .zoom-label').off('click').click(
                  function () {
                    var filePath = $(this).siblings(
                        'input[type="hidden"]').val();
                    window.open(filePath);
                  })
            }
            else if (result.code == 9999) {
              layer.msg(result.msg, {time: 1000});
              wzERP.Common.TimeoutLogin();
              return false;
            }
            else {
              console.log('个体资料获取失败!');
            }
          })
      //渲染第二页
      function templateRenderPage1() {
        $.post('/customer/erpContactInformation/queryAll', {custId: id},
            function (result) {
              if (result.code == 0) {
                renderData.contact = result.data;//联系方式渲染数据
                if (renderData.contact == null || renderData.contact.length
                    == 0) {
                  renderData.contact = ''
                  var tplBox = $modal.find('#modal_contact_viewedit');
                  tplBox.empty();
                } else {
                  var contactId = renderData.contact.contactType; //获取联系人类型id
                  //获取数据词典联系人类型
                  //根据联系人类型id获取名
                  $.get(
                      '/finance/erpAccountReceivable/querydictionDetailListByCode?code=contactsType',
                      function (result) {
                        if (result.code == 0) {
                          var _data = result.data;
                          var contactObj = {}
                          _data.forEach(function (val) {
                            contactObj[val.dictionaryDetailKey] = val.name;
                          });
                          renderData.contact.forEach(function (val) {
                            val.contactTypeName = contactObj[val.contactType] //获取联系人类型名
                          });
                          //渲染页面
                          var tplBox = $modal.find('#modal_contact_viewedit');
                          tplBox.empty().html(
                              template('modalTpl_addPersonal_page1',
                                  renderData));
                          //添加联系人功能初始化
                          contactFunction('#' + config.modalBox
                              + ' #modal_contact_viewedit');
                          $modal.find('.select-ui-box select').dropdown();
                          //解决在查看没法放大的bug
                          //图片
                          $modal.find('.cop-info-box .zoom-label').off(
                              'click').click(function () {
                            var filePath = $(this).siblings(
                                'input[type="hidden"]').val();
                            file.openBigPic('#bigPicShowLayer', filePath);
                          })
                          //pdf
                          $modal.find('.enterprise-bk .zoom-label').off(
                              'click').click(function () {
                            var filePath = $(this).siblings(
                                'input[type="hidden"]').val();
                            window.open(filePath);
                          })
                        }
                      });
                }
                hasRenderContact = true;//已渲染联系方式
              }
              else if (result.code == 9999) {
                layer.msg(result.msg, {time: 1000});
                wzERP.Common.TimeoutLogin();
                return false;
              }
            })
      }

      //渲染第三页
      function templateRenderPage2() {
        $.post('/customer/erpInvoiceHeaderManage/findAll', {custId: id},
            function (result) {
              if (result.code == 9999) {
                layer.msg(result.msg, {time: 1000});
                wzERP.Common.TimeoutLogin();
                return false;
              }
              renderData.invoice = result.data;//发票抬头渲染数据
              if (renderData.invoice == null || renderData.invoice.length
                  == 0) {
                renderData.invoice = ''
              }
              var tplBox = $modal.find('#modal_invoice_viewedit');
              tplBox.empty().html(
                  template('modalTpl_addPersonal_page2', renderData));
              //解决在查看没法放大的bug
              //图片
              $modal.find('.cop-info-box .zoom-label').off('click').click(
                  function () {
                    var filePath = $(this).siblings(
                        'input[type="hidden"]').val();
                    file.openBigPic('#bigPicShowLayer', filePath);
                  })
              //pdf
              $modal.find('.enterprise-bk .zoom-label').off('click').click(
                  function () {
                    var filePath = $(this).siblings(
                        'input[type="hidden"]').val();
                    window.open(filePath);
                  })
              hasRenderInvoice = true;//已渲染发票抬头
            })
      }
    }

    //查看其它组织客户
    function handleOther() {
      var renderData = {} //渲染的数据
      //初始化事件
      var $modal = $('#' + config.modalBox);//获取对应模态框
      $modal.modal({
        closable: false,
        transition: 'fade'
      }).modal('show');//弹窗
      $modal.find('.ui.header .act-type').text('组织详情');
      $modal.find('.content > .tab-box').addClass('view-mode').removeClass(
          'edit-mode');//查看模式
      $modal.find('.actions').hide();//隐藏弹窗底部操作框
      $modal.find('.tabular.menu .item').tab();//tab切换开启
      $modal.find('.ui.tabular .item').eq(0).addClass('active').siblings(
          '.item').removeClass('active');
      $modal.find('.ui.tab').eq(0).addClass('active').siblings(
          '.tab').removeClass('active');//默认显示第一页

      //联系和发票是否已渲染
      var hasRenderContact = false;
      var hasRenderInvoice = false;

      //tab导航点击加载事件
      $modal.on('click', '.ui.tabular.menu .item', function () {
        var pageIndex = $(this).index(); //获取当前页的tab索引
        switch (pageIndex) {
          case 1:
            if (!hasRenderContact) {
              templateRenderPage1()
            }
            break;
          case 2:
            if (!hasRenderInvoice) {
              templateRenderPage2()
            }
            break;
          default:
            return false;
        }
      })
      //渲染第一页
      $.post('/customer/findById', {id: id}, function (result) {
        if (result.code == 0) {
          renderData.otherData = result.data;//其它组织资料渲染数据
          console.log(result);
          //数据渲染
          var tplBox = $modal.find('#modal_other_data');
          tplBox.empty().html(template(config.tpl.page0, renderData));
          //解决在查看没法放大的bug
          //图片
          $modal.find('.cop-info-box .zoom-label').off('click').click(
              function () {
                var filePath = $(this).siblings('input[type="hidden"]').val();
                file.openBigPic('#bigPicShowLayer', filePath);
              })
          //pdf
          $modal.find('.enterprise-bk .zoom-label').off('click').click(
              function () {
                var filePath = $(this).siblings('input[type="hidden"]').val();
                window.open(filePath);
              })
        }
        else if (result.code == 9999) {
          layer.msg(result.msg, {time: 1000});
          wzERP.Common.TimeoutLogin();
          return false;
        }
        else {
          console.log('组织资料获取失败!');
        }
      })
      //渲染第二页
      function templateRenderPage1() {
        $.post('/customer/erpContactInformation/queryAll', {custId: id},
            function (result) {
              if (result.code == 0) {
                renderData.contact = result.data;//联系方式渲染数据
                if (renderData.contact == null || renderData.contact.length
                    == 0) {
                  renderData.contact = '';
                  var tplBox = $modal.find('#modal_contact_viewedit');
                  tplBox.empty();
                } else {
                  var contactId = renderData.contact.contactType; //获取联系人类型id
                  //获取数据词典联系人类型
                  //根据联系人类型id获取名
                  $.get(
                      '/finance/erpAccountReceivable/querydictionDetailListByCode?code=contactsType',
                      function (result) {
                        if (result.code == 0) {
                          var _data = result.data;
                          var contactObj = {}
                          _data.forEach(function (val) {
                            contactObj[val.dictionaryDetailKey] = val.name;
                          });
                          renderData.contact.forEach(function (val) {
                            val.contactTypeName = contactObj[val.contactType] //获取联系人类型名
                          });
                          //渲染页面
                          var tplBox = $modal.find('#modal_contact_viewedit');
                          tplBox.empty().html(
                              template('modalTpl_addOther_page1', renderData));
                          //添加联系人功能初始化
                          contactFunction('#' + config.modalBox
                              + ' #modal_contact_viewedit');
                          $modal.find('.select-ui-box select').dropdown();
                          //解决在查看没法放大的bug
                          //图片
                          $modal.find('.cop-info-box .zoom-label').off(
                              'click').click(function () {
                            var filePath = $(this).siblings(
                                'input[type="hidden"]').val();
                            file.openBigPic('#bigPicShowLayer', filePath);
                          })
                          //pdf
                          $modal.find('.enterprise-bk .zoom-label').off(
                              'click').click(function () {
                            var filePath = $(this).siblings(
                                'input[type="hidden"]').val();
                            window.open(filePath);
                          })
                        }
                      });
                }
                hasRenderContact = true;//已渲染联系方式
              }
              else if (result.code == 9999) {
                layer.msg(result.msg, {time: 1000});
                wzERP.Common.TimeoutLogin();
                return false;
              }
            })
      }

      //渲染第三页
      function templateRenderPage2() {
        $.post('/customer/erpInvoiceHeaderManage/findAll', {custId: id},
            function (result) {
              if (result.code == 9999) {
                layer.msg(result.msg, {time: 1000});
                wzERP.Common.TimeoutLogin();
                return false;
              }
              renderData.invoice = result.data;//发票抬头渲染数据
              if (renderData.invoice == null || renderData.invoice.length
                  == 0) {
                renderData.invoice = ''
              }
              var tplBox = $modal.find('#modal_invoice_viewedit');
              tplBox.empty().html(
                  template('modalTpl_addOther_page2', renderData));
              //解决在查看没法放大的bug
              //图片
              $modal.find('.cop-info-box .zoom-label').off('click').click(
                  function () {
                    var filePath = $(this).siblings(
                        'input[type="hidden"]').val();
                    file.openBigPic('#bigPicShowLayer', filePath);
                  })
              //pdf
              $modal.find('.enterprise-bk .zoom-label').off('click').click(
                  function () {
                    var filePath = $(this).siblings(
                        'input[type="hidden"]').val();
                    window.open(filePath);
                  })
              hasRenderInvoice = true;//已渲染发票抬头
            })
      }
    }

  });

  //编辑渲染事件
  var hasRunEnterpriseFuncEdit = {
    contact: false,
    invoice: false
  };
  var hasRunPersonalFuncEdit = {
    contact: false,
    invoice: false
  };
  var hasRunOtherFuncEdit = {
    contact: false,
    invoice: false
  };

  //编辑客户
  $('#file').on('click', '.editBtn', function () {
    var id = $(this).data('id');
    $('#cust').val(id);
    var type = $('#file >.tabular.menu').find('.item.active').data('type');
    var config = {}
    switch (type) {
      case 'enterprise':
        config = {
          modalBox: 'modal_addEnterprise_viewedit',
          tpl: {
            page0: 'modalTpl_addEnterprise_page0',//企业资料
            page1: 'modalTpl_addEnterprise_page1'//经营状况
          }
        };
        handleEnterprise();
        break;
      case 'personal':
        config = {
          modalBox: 'modal_addPersonal_viewedit',
          tpl: {
            page0: 'modalTpl_addPersonal_page0',//个体资料
          }
        };
        handlePersonal();
        break;
      case 'other':
        config = {
          modalBox: 'modal_addOther_viewedit',
          tpl: {
            page0: 'modalTpl_addOther_page0',//其它组织资料
          }
        };
        handleOther();
        break;
      default:
        return false;
    }
    ;
    //编辑企业客户
    function handleEnterprise() {
      var renderData = {} //渲染的数据
      //初始化事件
      var $modal = $('#' + config.modalBox);//获取对应模态框
      $modal.modal({
        closable: false,
        transition: 'fade',
        onDeny: function () {

        },
        onHidden: function () {

        }
      }).modal('show');//弹窗
      $modal.find('.ui.header .act-type').text('编辑企业');
      $modal.find('.content > .tab-box').removeClass('view-mode').addClass(
          'edit-mode');//去掉查看模式
      $modal.find('.actions').show();//显示弹窗底部操作框
      $modal.find('.tabular.menu .item').off('click');//去掉tab事件
      $modal.find('.ui.tabular .item').eq(0).addClass('active').siblings(
          '.item').removeClass('active');
      $modal.find('.ui.tab').eq(0).addClass('active').siblings(
          '.tab').removeClass('active');//默认显示第一页
      var $tabHeader = $modal.find('.ui.tabular.menu .item');//获取tab头
      var $tab = $modal.find('.ui.tab');//获取tab
      var $button_prev = $modal.find('.actions .prev');//获取上一步按钮
      var $button_next = $modal.find('.actions .savenext');//获取保存并下一步按钮
      var index_tab = $modal.find('.ui.tab.active').index() - 1;//获取当前tab的索引

      var canNextStep = true;//声明步骤权限

      //初始化
      actFromTabIndex(index_tab);
      showTab(index_tab);

      //联系和发票是否已渲染
      var hasRenderContact = false;
      var hasRenderInvoice = false;

      //保存下一步操作
      $modal.find('.savenext').off('click').click(function () {
        if (!canNextStep) {  //是否能下一步
          return false;
        }
        canNextStep = false;
        //获取表单
        var form_ele = '#' + config.modalBox + ' .ui.tab.active .file-verifier';
        //表单验证
        if (index_tab == 0 && !!file.checkform(form_ele)) {//第一页验证必填项

          //location判断
          file.checkLocation(form_ele);
          /*--------错误提示和位置处理------S------*/
          var firstError = $(form_ele).find('.ui.field.error').eq(0);//获取第一个错误
          var firstErrorMsg = firstError.find('.ui.basic.red.label').text();
          if (firstErrorMsg == '' && firstError.find('.city-picker-span').length
              > 0) {
            firstErrorMsg = '省市区地址请全选!'
          }
          //获取第一个报error相对顶部的距离
          var curActive = $modal.find('.ui.tab.active');
          var topToWindow = firstError.offset().top;
          var scrollBoxToWindow = curActive.offset().top;
          var scrollLength = curActive.scrollTop();
          var verticalShift = topToWindow + scrollLength - scrollBoxToWindow;
          //滚动到error的位置
          curActive.scrollTop(verticalShift - 8);
          //获取error提示信息
          layer.msg(firstErrorMsg, {icon: 2});
          /*--------错误提示和位置处理------E------*/

          canNextStep = true;
          return false;
        }
        //ajax保存当前页
        var obj = formSerializeToObj(form_ele);
        //根据当前页执行函数
        switch (index_tab) {
          case 0:
            var canMove = handleEnterpriseData();//企业资料处理
            if (!canMove) {
              return false
            }//操作有误无法下一步
            if (!hasRenderContact) {
              templateRenderPage1()
            }
            break;
          case 1:
            handleContact();//联系方式处理
            if (!hasRenderInvoice) {
              templateRenderPage2()
            }
            break;
          case 2:
            handleInvoice();//发票抬头处理
            break;
          default:
            return false;
        }

        //跳转下一页
        index_tab++;
        actFromTabIndex(index_tab);
        showTab(index_tab);

        //跳转步骤处理
        //企业资料处理
        function handleEnterpriseData() {
          //form提交前的name处理--Start
          //(注册资本单位转为分)
          var registeredCapital = $modal.find(
              '.basic-info input[name="registeredCapitalValidate"]').val();
          var unit = 6;//万元转分
          var registeredCapital = registeredCapital * Math.pow(10, unit);
          $modal.find('.basic-info input[name="registeredCapital"]').val(
              registeredCapital);
          //form提交前的name处理--End

          //form提交前保存客户标签
          var clientTags = [], canApprove = true;
          var tagItem = $('#' + config.modalBox + ' .cus-tags-box .tag-item');
          if (tagItem.length > 0) {
            tagItem.each(function () {
              var tagVal = $(this).find('input').val();
              var tagId = $(this).find('input').data('id');
              canApprove = $.trim(tagVal) == '' ? false : true;
              clientTags.push({
                id: tagId,
                value: tagVal
              });
            })
          }
          if (!canApprove) {
            layer.msg('客户标签不能留空!', {icon: 5});
            canNextStep = true;
            return false;//有空标签不允许通过
          }
          //处理citycode
          var cityData = wzERP.Common.getCityData(
              '#' + config.modalBox + ' #city');
          var hasAllData = true;
          //是否全选判断
          if (!cityData) {
            hasAllData = false;
          } else {
            for (var i = 0; i < cityData.length; i++) {
              if (cityData[i].value == undefined) {
                hasAllData = false;
              }
            }
          }
          if (hasAllData) {
            $('#' + config.modalBox + ' #provinceCode').val(cityData[1].value);
            $('#' + config.modalBox + ' #countyCode').val(cityData[3].value);
            $('#' + config.modalBox + ' #cityCode').val(cityData[2].value);
          } else {
            //省市区没全选情况下
            layer.msg('省市区地址请全选!', {icon: 5});
            //定位到顶部
            var curActive = $modal.find('.ui.tab.active');
            curActive.scrollTop(0);
            //标红error
            curActive.find('.city-picker-input').parents(
                '.ui.input.field').addClass('error');
            canNextStep = true;
            return false;
          }
          //转数字
          var formObj = formSerializeToObj(
              '#' + config.modalBox + ' .ui.tab.active .file-verifier');
          if (formObj['registeredCapital']) {
            formObj['registeredCapital'] = parseInt(
                formObj['registeredCapital']);
          }
          formObj['customerType'] = 0;//企业客户
          //更新添加id
          formObj['id'] = id;
          $.ajax({
            type: "POST",
            url: '/customer/addOrUpdate',
            data: formObj,
            success: function (result) {
              if (result.code == 0) {
                layer.msg('保存成功!', {icon: 7});
                canNextStep = true;
                if (clientTags.length == 0) {
                  return false
                }//没标签则不提交

                //获取客户id后批量上传客户标签
                var postArr = [];
                for (var i = 0; i < clientTags.length; i++) {
                  postArr.push({
                    "custId": id,
                    "id": clientTags[i].id,
                    "labelName": clientTags[i].value
                  })
                }
                if (postArr.length > 0) {
                  $.ajax({
                    type: "POST",
                    url: file.interface.batchAddOrUpdate,
                    contentType: "application/json",
                    dataType: "json",
                    data: JSON.stringify(postArr),
                    success: function (data) {
                      console.log('客户标签上传', data.msg);
                    },
                    error: function () {
                      layer.msg('客户标签保存失败!', {icon: 5});
                    }
                  });
                }
              }
              else if (result.code == 9999) {
                layer.msg(result.msg, {time: 1000});
                wzERP.Common.TimeoutLogin();
                return false;
              }
              else {
                layer.msg(result.msg, {icon: 5});
                canNextStep = true;
              }
            }
          });
          return true;
        }

        //联系方式处理
        function handleContact() {
          canNextStep = true;
        }

        //发票抬头处理
        function handleInvoice() {
          canNextStep = true;
        }
      });

      //上一步操作
      $modal.find('.actions .prev').off('click').click(function () {
        index_tab--;
        actFromTabIndex(index_tab);
        showTab(index_tab);
      });

      //根据tab索引显示隐藏按钮
      function actFromTabIndex(i) {
        /*Arg Guide
         @ i 要显示的tab索引
         */
        if (typeof i == 'number') {
          if (i == 0) {
            $button_prev.hide();
            $button_next.text('保存并下一步')
          } else {
            $button_prev.show();
            $button_next.text('下一步');
          }
          //显示隐藏保存按钮
          i == ($tab.length - 1) ? $button_next.hide() : $button_next.show();
        }
      }

      //显示指定的tab
      function showTab(i) {
        /*Arg Guide
         @ i 要显示的tab索引
         */
        $tabHeader.eq(i).addClass('active').siblings('.item').removeClass(
            'active');
        $tab.eq(i).addClass('active').siblings('.ui.tab').removeClass('active');
        $modal.find('.ui.tab.active').scrollTop(0);//滚动到顶部
      }

      //渲染第一页
      $.post('/customer/findById', {id: id}, function (result) {
        if (result.code == 0) {
          renderData.enterpData = result.data;//企业资料渲染数据
          console.log(result);
          /*获取地标*/
          var provinceName = result.data.provinceName;
          var cityName = result.data.cityName;
          var countyName = result.data.countyName;
          /*获取已选的状态*/
          var dictState = {
            enterpriseAppearance: result.data.enterpriseStatusCode,
            entrepreneurial: result.data.enterpriseNatureCode,
            industry: result.data.industryCode,
          }
          //获取客户标签
          $.get('/customer/erpCustomerLabel/findCusIdAll', {id: id},
              function (result) {
                if (result.code == 0) {
                  renderData.enterpData.custLabels = result.data;
                  console.log('标签列表', result.data);
                  //数据渲染
                  var tplBox = $modal.find('#modal_enterprise_data');
                  tplBox.empty().html(template(config.tpl.page0, renderData));
                  $modal.find("#city").citypicker({
                    province: provinceName,
                    city: cityName,
                    district: countyName
                  });
                  //标签事件化
                  tagFunction('#' + config.modalBox + ' .cus-tags-box');
                  //单个日期
                  wzERP.Common.singleDate(
                      '#' + config.modalBox + ' .single-date');
                  //起始日期
                  wzERP.Common.inlineDate(
                      '#' + config.modalBox + ' .rangestart',
                      '#' + config.modalBox + ' .rangeend');
                  //开启验证
                  file.verifier('#' + config.modalBox + ' .file-verifier');
                  /*---编辑调用数据词典--S---*/
                  //企业状态
                  $.get(
                      '/finance/erpAccountReceivable/querydictionDetailListByCode?code=enterpriseAppearance',
                      function (result) {
                        var $options = '<option value="">请选择</option>';
                        if (result.code == 0) {
                          var _data = result.data;
                          _data.forEach(function (val) {
                            if (val.name == dictState.enterpriseAppearance) {
                              $options += '<option value="' + val.id
                                  + '" selected>' + val.name + '</option>';
                            } else {
                              $options += '<option value="' + val.id + '">'
                                  + val.name + '</option>';
                            }
                          })
                        }
                        $modal.find('#enterpriseStatusCodeId').empty().append(
                            $options);
                      });
                  //企业性质
                  $.get(
                      '/finance/erpAccountReceivable/querydictionDetailListByCode?code=entrepreneurial',
                      function (result) {
                        var $options = '<option value="">请选择</option>';
                        if (result.code == 0) {
                          var _data = result.data;
                          _data.forEach(function (val) {
                            if (val.name == dictState.entrepreneurial) {
                              $options += '<option value="' + val.id
                                  + '" selected>' + val.name + '</option>';
                            } else {
                              $options += '<option value="' + val.id + '">'
                                  + val.name + '</option>';
                            }
                          })
                        }
                        $modal.find('#enterpriseNatureCodeId').empty().append(
                            $options);
                      });
                  //行业
                  $.get(
                      '/finance/erpAccountReceivable/querydictionDetailListByCode?code=industry',
                      function (result) {
                        var $options = '<option value="">请选择</option>';
                        if (result.code == 0) {
                          var _data = result.data;
                          _data.forEach(function (val) {
                            if (val.name == dictState.industry) {
                              $options += '<option value="' + val.id
                                  + '" selected>' + val.name + '</option>';
                            } else {
                              $options += '<option value="' + val.id + '">'
                                  + val.name + '</option>';
                            }
                          })
                        }
                        $modal.find('#industryCodeId').empty().append($options);
                      });
                  /*---编辑调用数据词典--E---*/
                  //解决在编辑没法放大的bug
                  //图片
                  $modal.find('.cop-info-box .zoom-label').off('click').click(
                      function () {
                        var filePath = $(this).siblings(
                            'input[type="hidden"]').val();
                        file.openBigPic('#bigPicShowLayer', filePath);
                      })
                  //pdf
                  $modal.find('.enterprise-bk .zoom-label').off('click').click(
                      function () {
                        var filePath = $(this).siblings(
                            'input[type="hidden"]').val();
                        window.open(filePath);
                      })
                }
              })
        }
        else if (result.code == 9999) {
          layer.msg(result.msg, {time: 1000});
          wzERP.Common.TimeoutLogin();
          return false;
        }
        else {
          console.log('企业资料获取失败!');
        }
      })
      //渲染第二页
      function templateRenderPage1() {
        $.post('/customer/erpContactInformation/queryAll', {custId: id},
            function (result) {
              if (result.code == 0) {
                renderData.contact = result.data;//联系方式渲染数据
                if (renderData.contact == null || renderData.contact.length
                    == 0) {
                  renderData.contact = ''
                  //渲染页面
                  var tplBox = $modal.find('#modal_contact_viewedit');
                  tplBox.empty().html(
                      template('modalTpl_addEnterprise_page3', renderData));
                  //添加联系人功能初始化
                  contactFunction(
                      '#' + config.modalBox + ' #modal_contact_viewedit',
                      !hasRunEnterpriseFuncEdit.contact);
                  hasRunEnterpriseFuncEdit.contact = true;
                  $modal.find('.select-ui-box select').dropdown();
                  //事件化
                  file.verifier('#' + config.modalBox + ' .file-verifier');
                  $('#' + config.modalBox + ' .ui.radio.checkbox').checkbox();
                  wzERP.Common.singleDate(
                      '#' + config.modalBox + ' .single-date');
                } else {
                  var contactId = renderData.contact.contactType; //获取联系人类型id
                  //获取数据词典联系人类型
                  //根据联系人类型id获取名
                  $.get(
                      '/finance/erpAccountReceivable/querydictionDetailListByCode?code=contactsType',
                      function (result) {
                        if (result.code == 0) {
                          var _data = result.data;
                          var contactObj = {}
                          _data.forEach(function (val) {
                            contactObj[val.dictionaryDetailKey] = val.name;
                          });
                          renderData.contact.forEach(function (val) {
                            val.contactTypeName = contactObj[val.contactType] //获取联系人类型名
                          });
                          //渲染页面
                          var tplBox = $modal.find('#modal_contact_viewedit');
                          tplBox.empty().html(
                              template('modalTpl_addEnterprise_page3',
                                  renderData));
                          console.log('111111111', renderData)
                          //添加联系人功能初始化
                          contactFunction('#' + config.modalBox
                              + ' #modal_contact_viewedit',
                              !hasRunEnterpriseFuncEdit.contact);
                          hasRunEnterpriseFuncEdit.contact = true;
                          $modal.find('.select-ui-box select').dropdown();
                          //事件化
                          file.verifier(
                              '#' + config.modalBox + ' .file-verifier');
                          $('#' + config.modalBox
                              + ' .ui.radio.checkbox').checkbox();
                          wzERP.Common.singleDate(
                              '#' + config.modalBox + ' .single-date');
                        }
                      });
                }
                hasRenderContact = true;//已渲染联系方式
              }
              else if (result.code == 9999) {
                layer.msg(result.msg, {time: 1000});
                wzERP.Common.TimeoutLogin();
                return false;
              }
            })
      }

      //渲染第三页
      function templateRenderPage2() {
        $.post('/customer/erpInvoiceHeaderManage/findAll', {custId: id},
            function (result) {
              if (result.code == 9999) {
                layer.msg(result.msg, {time: 1000});
                wzERP.Common.TimeoutLogin();
                return false;
              }
              renderData.invoice = result.data;//发票抬头渲染数据
              if (renderData.invoice == null || renderData.invoice.length
                  == 0) {
                renderData.invoice = ''
              }
              //渲染页面
              var tplBox = $modal.find('#modal_invoice_viewedit');
              tplBox.empty().html(
                  template('modalTpl_addEnterprise_page4', renderData));
              $('#' + config.modalBox + ' .ui.checkbox').checkbox();
              //添加发票功能初始化
              invoiceFunction(
                  '#' + config.modalBox + ' #modal_invoice_viewedit',
                  !hasRunEnterpriseFuncEdit.invoice);
              hasRunEnterpriseFuncEdit.invoice = true;
              file.uploadFilePdf(
                  '#' + config.modalBox + ' #modal_invoice_viewedit',
                  '#uploadProof_label', '#uploadProof_form');//一般纳税人证明
              $modal.find('.select-ui-box select').dropdown();
              //事件化
              file.verifier('#' + config.modalBox + ' .file-verifier');
              wzERP.Common.singleDate('#' + config.modalBox + ' .single-date');
              hasRenderInvoice = true;//已渲染发票抬头
            })
      }
    }

    //编辑个体客户
    function handlePersonal() {
      var renderData = {} //渲染的数据
      //初始化事件
      var $modal = $('#' + config.modalBox);//获取对应模态框
      $modal.modal({
        closable: false,
        transition: 'fade',
        onDeny: function () {

        },
        onHidden: function () {

        }
      }).modal('show');//弹窗
      $modal.find('.ui.header .act-type').text('编辑个体');
      $modal.find('.content > .tab-box').removeClass('view-mode').addClass(
          'edit-mode');//去掉查看模式
      $modal.find('.actions').show();//显示弹窗底部操作框
      $modal.find('.tabular.menu .item').off('click');//去掉tab事件
      $modal.find('.ui.tabular .item').eq(0).addClass('active').siblings(
          '.item').removeClass('active');
      $modal.find('.ui.tab').eq(0).addClass('active').siblings(
          '.tab').removeClass('active');//默认显示第一页
      var $tabHeader = $modal.find('.ui.tabular.menu .item');//获取tab头
      var $tab = $modal.find('.ui.tab');//获取tab
      var $button_prev = $modal.find('.actions .prev');//获取上一步按钮
      var $button_next = $modal.find('.actions .savenext');//获取保存并下一步按钮
      var index_tab = $modal.find('.ui.tab.active').index() - 1;//获取当前tab的索引
      //初始化
      actFromTabIndex(index_tab);
      showTab(index_tab);

      var canNextStep = true;//声明步骤权限

      //联系和发票是否已渲染
      var hasRenderContact = false;
      var hasRenderInvoice = false;

      //保存下一步操作
      $modal.find('.savenext').off('click').click(function () {
        if (!canNextStep) {  //是否能下一步
          return false;
        }
        canNextStep = false;
        //获取表单
        var form_ele = '#' + config.modalBox + ' .ui.tab.active .file-verifier';
        //表单验证
        if (index_tab == 0 && !!file.checkform(form_ele)) {//第一页验证必填项

          //location判断
          file.checkLocation(form_ele);
          /*--------错误提示和位置处理------S------*/
          var firstError = $(form_ele).find('.ui.field.error').eq(0);//获取第一个错误
          var firstErrorMsg = firstError.find('.ui.basic.red.label').text();
          if (firstErrorMsg == '' && firstError.find('.city-picker-span').length
              > 0) {
            firstErrorMsg = '省市区地址请全选!'
          }
          //获取第一个报error相对顶部的距离
          var curActive = $modal.find('.ui.tab.active');
          var topToWindow = firstError.offset().top;
          var scrollBoxToWindow = curActive.offset().top;
          var scrollLength = curActive.scrollTop();
          var verticalShift = topToWindow + scrollLength - scrollBoxToWindow;
          //滚动到error的位置
          curActive.scrollTop(verticalShift - 8);
          //获取error提示信息
          layer.msg(firstErrorMsg, {icon: 2});
          /*--------错误提示和位置处理------E------*/

          canNextStep = true;
          return false;
        }
        //ajax保存当前页
        var obj = formSerializeToObj(form_ele);
        //根据当前页执行函数
        switch (index_tab) {
          case 0:
            var canMove = handlePersonalData();//个体客户资料处理
            if (!canMove) {
              return false
            }//操作有误无法下一步
            if (!hasRenderContact) {
              templateRenderPage1()
            }
            break;
          case 1:
            handleContact();//联系方式处理
            if (!hasRenderInvoice) {
              templateRenderPage2()
            }
            break;
          case 2:
            handleInvoice();//发票抬头处理
            break;
          default:
            return false;
        }

        //跳转下一页
        index_tab++;
        actFromTabIndex(index_tab);
        showTab(index_tab);

        //跳转步骤处理
        //个体客户资料处理
        function handlePersonalData() {
          //处理citycode
          var cityData = wzERP.Common.getCityData(
              '#' + config.modalBox + ' #city');
          var hasAllData = true;
          //是否全选判断
          if (!cityData) {
            hasAllData = false;
          } else {
            for (var i = 0; i < cityData.length; i++) {
              if (cityData[i].value == undefined) {
                hasAllData = false;
              }
            }
          }
          if (hasAllData) {
            $('#' + config.modalBox + ' #provinceCode').val(cityData[1].value);
            $('#' + config.modalBox + ' #countyCode').val(cityData[3].value);
            $('#' + config.modalBox + ' #cityCode').val(cityData[2].value);
          } else {
            //省市区没全选情况下
            layer.msg('省市区地址请全选!', {icon: 5});
            //定位到顶部
            var curActive = $modal.find('.ui.tab.active');
            curActive.scrollTop(0);
            //标红error
            curActive.find('.city-picker-input').parents(
                '.ui.input.field').addClass('error');
            canNextStep = true;
            return false;
          }
          //转数字
          var formObj = formSerializeToObj(
              '#' + config.modalBox + ' .ui.tab.active .file-verifier');
          var individualId = $modal.find('#modal_personal_data').data('id');
          formObj['customerType'] = 1;//个体客户

          //更新添加id
          formObj['id'] = id;
          formObj['individualId'] = individualId;//个体表id
          $.ajax({
            type: "POST",
            url: '/customer/erpIndividualCustomer/addOrUpdate',
            data: formObj,
            success: function (result) {
              if (result.code == 0) {
                layer.msg('保存成功!', {icon: 7});
                canNextStep = true;
              }
              else if (result.code == 9999) {
                layer.msg(result.msg, {time: 1000});
                wzERP.Common.TimeoutLogin();
                return false;
              }
              else {
                layer.msg(result.msg, {icon: 5});
                canNextStep = true;
              }
            }
          });
          return true;
        }

        //联系方式处理
        function handleContact() {
          canNextStep = true;
        }

        //发票抬头处理
        function handleInvoice() {
          canNextStep = true;
        }
      });

      //上一步操作
      $modal.find('.actions .prev').off('click').click(function () {

        index_tab--;
        actFromTabIndex(index_tab);
        showTab(index_tab);
      });

      //根据tab索引显示隐藏按钮
      function actFromTabIndex(i) {
        /*Arg Guide
         @ i 要显示的tab索引
         */
        if (typeof i == 'number') {
          if (i == 0) {
            $button_prev.hide();
            $button_next.text('保存并下一步')
          } else {
            $button_prev.show();
            $button_next.text('下一步');
          }
          //显示隐藏保存按钮
          i == ($tab.length - 1) ? $button_next.hide() : $button_next.show();
        }
      }

      //显示指定的tab
      function showTab(i) {
        /*Arg Guide
         @ i 要显示的tab索引
         */
        $tabHeader.eq(i).addClass('active').siblings('.item').removeClass(
            'active');
        $tab.eq(i).addClass('active').siblings('.ui.tab').removeClass('active');
        $modal.find('.ui.tab.active').scrollTop(0);//滚动到顶部
      }

      //渲染第一页
      $.post('/customer/erpIndividualCustomer/findById', {id: id},
          function (result) {
            if (result.code == 0) {
              renderData.personalData = result.data;//企业资料渲染数据
              console.log(result);

              /*获取地标*/
              var provinceName = result.data.provinceName;
              var cityName = result.data.cityName;
              var countyName = result.data.countyName;
              //数据渲染
              var tplBox = $modal.find('#modal_personal_data');
              tplBox.empty().html(template(config.tpl.page0, renderData));
              tplBox.attr('data-id', result.data.individualId);
              $modal.find("#city").citypicker({
                province: provinceName,
                city: cityName,
                district: countyName
              });
              //标签事件化
              tagFunction('#' + config.modalBox + ' .cus-tags-box');
              //单个日期
              wzERP.Common.singleDate('#' + config.modalBox + ' .single-date');
              //起始日期
              wzERP.Common.inlineDate('#' + config.modalBox + ' .rangestart',
                  '#' + config.modalBox + ' .rangeend');
              //开启验证
              file.verifier('#' + config.modalBox + ' .file-verifier');
              //checkbox功能开启
              $('#' + config.modalBox + ' .ui.checkbox').checkbox();
              //解决在编辑没法放大的bug
              //图片
              $modal.find('.cop-info-box .zoom-label').off('click').click(
                  function () {
                    var filePath = $(this).siblings(
                        'input[type="hidden"]').val();
                    file.openBigPic('#bigPicShowLayer', filePath);
                  })
              //pdf
              $modal.find('.enterprise-bk .zoom-label').off('click').click(
                  function () {
                    var filePath = $(this).siblings(
                        'input[type="hidden"]').val();
                    window.open(filePath);
                  })
            }
            else if (result.code == 9999) {
              layer.msg(result.msg, {time: 1000});
              wzERP.Common.TimeoutLogin();
              return false;
            }
            else {
              console.log('个人资料获取失败!');
            }
          })
      function templateRenderPage1() {
        //渲染第二页
        $.post('/customer/erpContactInformation/queryAll', {custId: id},
            function (result) {
              if (result.code == 0) {
                renderData.contact = result.data;//联系方式渲染数据
                if (renderData.contact == null || renderData.contact.length
                    == 0) {
                  renderData.contact = '';
                  //渲染页面
                  var tplBox = $modal.find('#modal_contact_viewedit');
                  tplBox.empty().html(
                      template('modalTpl_addPersonal_page1', renderData));
                  //添加联系人功能初始化
                  contactFunction(
                      '#' + config.modalBox + ' #modal_contact_viewedit',
                      !hasRunPersonalFuncEdit.contact);
                  hasRunPersonalFuncEdit.contact = true;
                  $modal.find('.select-ui-box select').dropdown();
                  //事件化
                  file.verifier('#' + config.modalBox + ' .file-verifier');
                  $('#' + config.modalBox + ' .ui.radio.checkbox').checkbox();
                  wzERP.Common.singleDate(
                      '#' + config.modalBox + ' .single-date');
                } else {
                  var contactId = renderData.contact.contactType; //获取联系人类型id
                  //获取数据词典联系人类型
                  //根据联系人类型id获取名
                  $.get(
                      '/finance/erpAccountReceivable/querydictionDetailListByCode?code=contactsType',
                      function (result) {
                        if (result.code == 0) {
                          var _data = result.data;
                          var contactObj = {}
                          _data.forEach(function (val) {
                            contactObj[val.dictionaryDetailKey] = val.name;
                          });
                          renderData.contact.forEach(function (val) {
                            val.contactTypeName = contactObj[val.contactType] //获取联系人类型名
                          });
                          //渲染页面
                          var tplBox = $modal.find('#modal_contact_viewedit');
                          tplBox.empty().html(
                              template('modalTpl_addPersonal_page1',
                                  renderData));
                          //添加联系人功能初始化
                          contactFunction('#' + config.modalBox
                              + ' #modal_contact_viewedit',
                              !hasRunPersonalFuncEdit.contact);
                          hasRunPersonalFuncEdit.contact = true;
                          $modal.find('.select-ui-box select').dropdown();
                          //事件化
                          file.verifier(
                              '#' + config.modalBox + ' .file-verifier');
                          $('#' + config.modalBox
                              + ' .ui.radio.checkbox').checkbox();
                          wzERP.Common.singleDate(
                              '#' + config.modalBox + ' .single-date');
                        }
                      });
                }
                hasRenderContact = true;//已渲染联系方式
              }
              else if (result.code == 9999) {
                layer.msg(result.msg, {time: 1000});
                wzERP.Common.TimeoutLogin();
                return false;
              }
            })
      }

      //渲染第三页
      function templateRenderPage2() {
        $.post('/customer/erpInvoiceHeaderManage/findAll', {custId: id},
            function (result) {
              if (result.code == 9999) {
                layer.msg(result.msg, {time: 1000});
                wzERP.Common.TimeoutLogin();
                return false;
              }
              renderData.invoice = result.data;//发票抬头渲染数据
              if (renderData.invoice == null || renderData.invoice.length
                  == 0) {
                renderData.invoice = ''
              }
              //渲染页面
              var tplBox = $modal.find('#modal_invoice_viewedit');
              tplBox.empty().html(
                  template('modalTpl_addPersonal_page2', renderData));
              //添加发票功能初始化
              invoiceFunction(
                  '#' + config.modalBox + ' #modal_invoice_viewedit',
                  !hasRunPersonalFuncEdit.invoice);
              hasRunPersonalFuncEdit.invoice = true;
              file.uploadFilePdf(
                  '#' + config.modalBox + ' #modal_invoice_viewedit',
                  '#uploadProof_label', '#uploadProof_form');//一般纳税人证明
              $modal.find('.select-ui-box select').dropdown();
              //事件化
              file.verifier('#' + config.modalBox + ' .file-verifier');
              $('#' + config.modalBox + ' .ui.checkbox').checkbox();
              wzERP.Common.singleDate('#' + config.modalBox + ' .single-date');
              hasRenderInvoice = true;//已渲染发票抬头
            })
      }
    }

    //编辑其它组织客户
    function handleOther() {
      var renderData = {} //渲染的数据
      //初始化事件
      var $modal = $('#' + config.modalBox);//获取对应模态框
      $modal.modal({
        closable: false,
        transition: 'fade',
        onDeny: function () {

        },
        onHidden: function () {

        }
      }).modal('show');//弹窗
      $modal.find('.ui.header .act-type').text('编辑组织');
      $modal.find('.content > .tab-box').removeClass('view-mode').addClass(
          'edit-mode');//去掉查看模式
      $modal.find('.actions').show();//显示弹窗底部操作框
      $modal.find('.tabular.menu .item').off('click');//去掉tab事件
      $modal.find('.ui.tabular .item').eq(0).addClass('active').siblings(
          '.item').removeClass('active');
      $modal.find('.ui.tab').eq(0).addClass('active').siblings(
          '.tab').removeClass('active');//默认显示第一页
      var $tabHeader = $modal.find('.ui.tabular.menu .item');//获取tab头
      var $tab = $modal.find('.ui.tab');//获取tab
      var $button_prev = $modal.find('.actions .prev');//获取上一步按钮
      var $button_next = $modal.find('.actions .savenext');//获取保存并下一步按钮
      var index_tab = $modal.find('.ui.tab.active').index() - 1;//获取当前tab的索引
      //初始化
      actFromTabIndex(index_tab);
      showTab(index_tab);

      var canNextStep = true;//声明步骤权限

      //联系和发票是否已渲染
      var hasRenderContact = false;
      var hasRenderInvoice = false;

      //保存下一步操作
      $modal.find('.savenext').off('click').click(function () {
        if (!canNextStep) {  //是否能下一步
          return false;
        }
        canNextStep = false;
        //获取表单
        var form_ele = '#' + config.modalBox + ' .ui.tab.active .file-verifier';
        //表单验证
        if (index_tab == 0 && !!file.checkform(form_ele)) {//第一页验证必填项

          //location判断
          file.checkLocation(form_ele);
          /*--------错误提示和位置处理------S------*/
          var firstError = $(form_ele).find('.ui.field.error').eq(0);//获取第一个错误
          var firstErrorMsg = firstError.find('.ui.basic.red.label').text();
          if (firstErrorMsg == '' && firstError.find('.city-picker-span').length
              > 0) {
            firstErrorMsg = '省市区地址请全选!'
          }
          //获取第一个报error相对顶部的距离
          var curActive = $modal.find('.ui.tab.active');
          var topToWindow = firstError.offset().top;
          var scrollBoxToWindow = curActive.offset().top;
          var scrollLength = curActive.scrollTop();
          var verticalShift = topToWindow + scrollLength - scrollBoxToWindow;
          //滚动到error的位置
          curActive.scrollTop(verticalShift - 8);
          //获取error提示信息
          layer.msg(firstErrorMsg, {icon: 2});
          /*--------错误提示和位置处理------E------*/

          canNextStep = true;
          return false;
        }
        //ajax保存当前页
        var obj = formSerializeToObj(form_ele);
        //根据当前页执行函数
        switch (index_tab) {
          case 0:
            var canMove = handlePersonalData();//个体客户资料处理
            if (!canMove) {
              return false
            }//操作有误无法下一步
            if (!hasRenderContact) {
              templateRenderPage1()
            }
            break;
          case 1:
            handleContact();//联系方式处理
            if (!hasRenderInvoice) {
              templateRenderPage2()
            }
            break;
          case 2:
            handleInvoice();//发票抬头处理
            break;
          default:
            return false;
        }

        //跳转下一页
        index_tab++;
        actFromTabIndex(index_tab);
        showTab(index_tab);

        //跳转步骤处理
        //个体客户资料处理
        function handlePersonalData() {
          //处理citycode
          var cityData = wzERP.Common.getCityData(
              '#' + config.modalBox + ' #city');
          var hasAllData = true;
          //是否全选判断
          if (!cityData) {
            hasAllData = false;
          } else {
            for (var i = 0; i < cityData.length; i++) {
              if (cityData[i].value == undefined) {
                hasAllData = false;
              }
            }
          }
          if (hasAllData) {
            $('#' + config.modalBox + ' #provinceCode').val(cityData[1].value);
            $('#' + config.modalBox + ' #countyCode').val(cityData[3].value);
            $('#' + config.modalBox + ' #cityCode').val(cityData[2].value);
          } else {
            //省市区没全选情况下
            layer.msg('省市区地址请全选!', {icon: 5});
            //定位到顶部
            var curActive = $modal.find('.ui.tab.active');
            curActive.scrollTop(0);
            //标红error
            curActive.find('.city-picker-input').parents(
                '.ui.input.field').addClass('error');
            canNextStep = true;
            return false;
          }
          //转数字
          var formObj = formSerializeToObj(
              '#' + config.modalBox + ' .ui.tab.active .file-verifier');
          formObj['customerType'] = 2;//其它组织客户
          //更新添加id
          formObj['id'] = id;
          $.ajax({
            type: "POST",
            url: '/customer/addOrUpdate',
            data: formObj,
            success: function (result) {
              if (result.code == 0) {
                layer.msg('保存成功!', {icon: 7});
                canNextStep = true;
              }
              else if (result.code == 9999) {
                layer.msg(result.msg, {time: 1000});
                wzERP.Common.TimeoutLogin();
                return false;
              }
              else {
                layer.msg(result.msg, {icon: 5});
                canNextStep = true;
              }
            }
          });
          return true;
        }

        //联系方式处理
        function handleContact() {
          canNextStep = true;
        }

        //发票抬头处理
        function handleInvoice() {
          canNextStep = true;
        }
      });

      //上一步操作
      $modal.find('.actions .prev').off('click').click(function () {

        index_tab--;
        actFromTabIndex(index_tab);
        showTab(index_tab);
      });

      //根据tab索引显示隐藏按钮
      function actFromTabIndex(i) {
        /*Arg Guide
         @ i 要显示的tab索引
         */
        if (typeof i == 'number') {
          if (i == 0) {
            $button_prev.hide();
            $button_next.text('保存并下一步')
          } else {
            $button_prev.show();
            $button_next.text('下一步');
          }
          //显示隐藏保存按钮
          i == ($tab.length - 1) ? $button_next.hide() : $button_next.show();
        }
      }

      //显示指定的tab
      function showTab(i) {
        /*Arg Guide
         @ i 要显示的tab索引
         */
        $tabHeader.eq(i).addClass('active').siblings('.item').removeClass(
            'active');
        $tab.eq(i).addClass('active').siblings('.ui.tab').removeClass('active');
        $modal.find('.ui.tab.active').scrollTop(0);//滚动到顶部
      }

      //渲染第一页
      $.post('/customer/findById', {id: id}, function (result) {
        if (result.code == 0) {
          renderData.otherData = result.data;//企业资料渲染数据
          console.log(result);
          /*获取地标*/
          var provinceName = result.data.provinceName;
          var cityName = result.data.cityName;
          var countyName = result.data.countyName;
          /*获取已选的状态*/
          var dictState = {
            organizationCategoryName: result.data.organizationCategoryName,
            enterpriseStatusCode: result.data.enterpriseStatusCode,
          }
          //数据渲染
          var tplBox = $modal.find('#modal_other_data');
          tplBox.empty().html(template(config.tpl.page0, renderData));
          $modal.find("#city").citypicker({
            province: provinceName,
            city: cityName,
            district: countyName
          });
          //单个日期
          wzERP.Common.singleDate('#' + config.modalBox + ' .single-date');
          //起始日期
          wzERP.Common.inlineDate('#' + config.modalBox + ' .rangestart',
              '#' + config.modalBox + ' .rangeend');
          //开启验证
          file.verifier('#' + config.modalBox + ' .file-verifier');
          /*---编辑调用数据词典--S---*/
          //组织类别
          $.get(
              '/finance/erpAccountReceivable/querydictionDetailListByCode?code=organizationCategory',
              function (result) {
                var $options = '<option value="">请选择</option>';
                if (result.code == 0) {
                  var _data = result.data;
                  _data.forEach(function (val) {
                    if (val.name == dictState.organizationCategoryName) {
                      $options += '<option value="' + val.id + '" selected>'
                          + val.name + '</option>';
                    } else {
                      $options += '<option value="' + val.id + '">' + val.name
                          + '</option>';
                    }
                  })
                }
                $modal.find('#organizationCategoryCodeId').empty().append(
                    $options);
              });
          //企业状态
          $.get(
              '/finance/erpAccountReceivable/querydictionDetailListByCode?code=enterpriseAppearance',
              function (result) {
                var $options = '<option value="">请选择</option>';
                if (result.code == 0) {
                  var _data = result.data;
                  _data.forEach(function (val) {
                    if (val.name == dictState.enterpriseStatusCode) {
                      $options += '<option value="' + val.id + '" selected>'
                          + val.name + '</option>';
                    } else {
                      $options += '<option value="' + val.id + '">' + val.name
                          + '</option>';
                    }
                  })
                }
                $modal.find('#enterpriseStatusCodeId').empty().append($options);
              });
          /*---编辑调用数据词典--E---*/
          //解决在编辑没法放大的bug
          //图片
          $modal.find('.cop-info-box .zoom-label').off('click').click(
              function () {
                var filePath = $(this).siblings('input[type="hidden"]').val();
                file.openBigPic('#bigPicShowLayer', filePath);
              })
          //pdf
          $modal.find('.enterprise-bk .zoom-label').off('click').click(
              function () {
                var filePath = $(this).siblings('input[type="hidden"]').val();
                window.open(filePath);
              })
        }
        else if (result.code == 9999) {
          layer.msg(result.msg, {time: 1000});
          wzERP.Common.TimeoutLogin();
          return false;
        }
        else {
          console.log('企业资料获取失败!');
        }
      })
      //渲染第二页
      function templateRenderPage1() {
        $.post('/customer/erpContactInformation/queryAll', {custId: id},
            function (result) {
              if (result.code == 0) {
                renderData.contact = result.data;//联系方式渲染数据
                if (renderData.contact == null || renderData.contact.length
                    == 0) {
                  renderData.contact = '';
                  //渲染页面
                  var tplBox = $modal.find('#modal_contact_viewedit');
                  tplBox.empty().html(
                      template('modalTpl_addOther_page1', renderData));
                  //添加联系人功能初始化
                  contactFunction(
                      '#' + config.modalBox + ' #modal_contact_viewedit',
                      !hasRunOtherFuncEdit.contact);
                  hasRunOtherFuncEdit.contact = true;
                  $modal.find('.select-ui-box select').dropdown();
                  //事件化
                  file.verifier('#' + config.modalBox + ' .file-verifier');
                  $('#' + config.modalBox + ' .ui.radio.checkbox').checkbox();
                  wzERP.Common.singleDate(
                      '#' + config.modalBox + ' .single-date');
                } else {
                  var contactId = renderData.contact.contactType; //获取联系人类型id
                  //获取数据词典联系人类型
                  //根据联系人类型id获取名
                  $.get(
                      '/finance/erpAccountReceivable/querydictionDetailListByCode?code=contactsType',
                      function (result) {
                        if (result.code == 0) {
                          var _data = result.data;
                          var contactObj = {}
                          _data.forEach(function (val) {
                            contactObj[val.dictionaryDetailKey] = val.name;
                          });
                          renderData.contact.forEach(function (val) {
                            val.contactTypeName = contactObj[val.contactType] //获取联系人类型名
                          });
                          //渲染页面
                          var tplBox = $modal.find('#modal_contact_viewedit');
                          tplBox.empty().html(
                              template('modalTpl_addOther_page1', renderData));
                          //添加联系人功能初始化
                          contactFunction('#' + config.modalBox
                              + ' #modal_contact_viewedit',
                              !hasRunOtherFuncEdit.contact);
                          hasRunOtherFuncEdit.contact = true;
                          $modal.find('.select-ui-box select').dropdown();
                          //事件化
                          file.verifier(
                              '#' + config.modalBox + ' .file-verifier');
                          $('#' + config.modalBox
                              + ' .ui.radio.checkbox').checkbox();
                          wzERP.Common.singleDate(
                              '#' + config.modalBox + ' .single-date');
                        }
                      });
                }
                hasRenderContact = true;//已渲染联系方式
              }
              else if (result.code == 9999) {
                layer.msg(result.msg, {time: 1000});
                wzERP.Common.TimeoutLogin();
                return false;
              }
            })
      }

      //渲染第三页
      function templateRenderPage2() {
        $.post('/customer/erpInvoiceHeaderManage/findAll', {custId: id},
            function (result) {
              if (result.code == 9999) {
                layer.msg(result.msg, {time: 1000});
                wzERP.Common.TimeoutLogin();
                return false;
              }
              renderData.invoice = result.data;//发票抬头渲染数据
              if (renderData.invoice == null || renderData.invoice.length
                  == 0) {
                renderData.invoice = ''
              }
              //渲染页面
              var tplBox = $modal.find('#modal_invoice_viewedit');
              tplBox.empty().html(
                  template('modalTpl_addOther_page2', renderData));
              $('#' + config.modalBox + ' .ui.checkbox').checkbox();
              //添加发票功能初始化
              invoiceFunction(
                  '#' + config.modalBox + ' #modal_invoice_viewedit',
                  !hasRunOtherFuncEdit.invoice);
              hasRunOtherFuncEdit.invoice = true;
              file.uploadFilePdf(
                  '#' + config.modalBox + ' #modal_invoice_viewedit',
                  '#uploadProof_label', '#uploadProof_form');//一般纳税人证明
              $modal.find('.select-ui-box select').dropdown();
              //事件化
              file.verifier('#' + config.modalBox + ' .file-verifier');
              wzERP.Common.singleDate('#' + config.modalBox + ' .single-date');
              hasRenderInvoice = true;//已渲染发票抬头
            })
      }
    }
  });

  //删除客户
  $('#file').on('click', '.delBtn', function () {
    /*var id = $(this).data('id');
     $('#modalDelete').modal({
     closable: false,
     transition: 'fade',
     onApprove:function () {
     $.post('/customer/delete',{ id:id },function(data){
     if(data.code == 0){
     layer.msg('删除成功', {icon: 7})
     var num = $('#file >.ui.tab.active').find('.page-show-select select').val();
     var type = $('#file >.tabular.menu').find('.item.active').data('type');
     file.showDataByPage(file[type],1,num);
     }else {
     layer.msg('删除失败', {icon: 5})
     }
     })
     }
     }).modal('show')*/
    var id = $(this).data('id');
    layer.alert('确定删除该客户信息吗？', {
          title: '提示信息',
          btn: ['取消', '确认'],
          btn1: function (index) {
            layer.close(index)
          },
          btn2: function () {
            $.post('/customer/delete', {id: id}, function (data) {
              if (data.code == 0) {
                layer.msg('删除成功', {icon: 7})
                var num = $('#file >.ui.tab.active').find(
                    '.page-show-select select').val();
                var type = $('#file >.tabular.menu').find('.item.active').data(
                    'type');
                file.showDataByPage(file[type], 1, num);
              }
              else if (data.code == 9999) {
                layer.msg(data.msg, {time: 1000});
                wzERP.Common.TimeoutLogin();
                return false;
              }
              else {
                layer.msg('删除失败', {icon: 5})
              }
            })
          }
        }
    );
  });

});

var file = {
  //接口
  interface: {
    queryPage: '/customer/queryPageJSON',//客户管理分页查询接口
    addOrUpdate: '/customer/addOrUpdate',//添加/更新客户基本信息
    //最新记录查找
    findLastOneData: '/customer/erpCustomerPsDataRep/findLastOne',//查找当前客户的最近一条数据报表记录接口
    findLastOneIpr: '/customer/erpPatentIprSituation/findLastOne',//查找当前客户知识产权专利最新记录
    findLastOneTrademark: '/customer/erpTrademarkIprSituation/findLast',//查找当前客户知识产权商标最新记录
    findLastOneCopyright: '/customer/erpCopyrightIprStatus/findLastOne',//查找当前客户知识产权版权最新记录
    findLastOneProject: '/customer/erpProjectIprStatus/findLastOne',//查找当前客户知识产权项目最新记录
    //批量添加
    batchAddOrUpdate: '/customer/erpCustomerLabel/batchAddOrUpdate',//客户标签批量添加更新接口
    addOrUpdateBatch: '/customer/erpCustomerPsDataRep/addOrUpdateBatch',//数据报表-批量添加和更新
    addOrUpdateBatchIpr: '/customer/erpPatentIprSituation/batchAddOrUpdate',//知识产权-专利-批量添加和更新
    addOrUpdateBatchTrademark: '/customer/erpTrademarkIprSituation/addOrUpdate',//知识产权-商标-批量添加和更新
    addOrUpdateBatchCopyright: '/customer/erpCopyrightIprStatus/batchAddOrUpdate',//知识产权-版权-批量添加和更新
    addOrUpdateBatchProject: '/customer/erpProjectIprStatus/batchAddOrUpdate',//知识产权-项目-批量添加和更新
    //其它信息
    otherAddOrUpdateOperate: '/customer/erpCustomerPsOther/addOrUpdate',//客户经营状况-其他 添加或者更新接口
    otherAddOrUpdateIpr: '/customer/erpOtherIprInformation/addOrUpdate',//客户知识产权-其他 添加或者更新接口
    //添加联系人
    addOrUpdateContact: '/customer/erpContactInformation/addOrUpdate',//联系方式的添加或者更新接口
  },
  //企业客户数据渲染
  enterprise: {
    search_ele: 'searchForm_enterprise',//搜索表单id
    searchkey: 'searchKey_enterprise',//搜索内容id
    city_ele: 'city_enterprise',//搜索地址id
    query_ele: 'query_enterprise',//查询按钮id
    page_ele: 'numberOf_enterprise',//选择页数id
    tpl_box: 'formData_enterprise',//模版盒子id
    tpl_ele: 'formTpl_enterprise',//模版渲染引擎id
    turnpage_ele: 'turnpage_enterprise',//分页id
    customerType: 0
  },
  //个体客户数据渲染
  personal: {
    search_ele: 'searchForm_personal',//搜索表单id
    searchkey: 'searchKey_personal',//搜索内容id
    city_ele: 'city_personal',//搜索地址id
    query_ele: 'query_personal',//查询按钮id
    page_ele: 'numberOf_personal',//选择页数id
    tpl_box: 'formData_personal',//模版盒子id
    tpl_ele: 'formTpl_personal',//模版渲染引擎id
    turnpage_ele: 'turnpage_personal',//分页id
    customerType: 1
  },
  //个体客户数据渲染
  other: {
    search_ele: 'searchForm_other',//搜索表单id
    searchkey: 'searchKey_other',//搜索内容id
    city_ele: 'city_other',//搜索地址id
    query_ele: 'query_other',//查询按钮id
    page_ele: 'numberOf_other',//选择页数id
    tpl_box: 'formData_other',//模版盒子id
    tpl_ele: 'formTpl_other',//模版渲染引擎id
    turnpage_ele: 'turnpage_other',//分页id
    customerType: 2
  },
  //获取当前页面内容
  showDataByPage: function (option, curr, num, searchKey, startDate, endDate,
      companyCode, provinceCode, cityCode, countyCode) {
    //option:客户配置
    //curr:当前页
    //num:每页显示条数
    //searchKey:搜索内容
    //startDate:开始时间
    //endDate:结束时间
    //companyCode:公司编码
    //provinceCode:省编码
    //cityCode:市编码
    //countyCode:县编码
    var _url = this.interface.queryPage;//获取接口地址
    $.post(_url, {
      current: curr || 1,
      pageSize: num || 10,
      searchKey: searchKey,
      startDate: startDate,
      endDate: endDate,
      customerType: option.customerType,
      companyCode: companyCode,
      provinceCode: provinceCode,
      cityCode: cityCode,
      countyCode: countyCode
    }, function (result) {
      if (result.code == 0) {
        //获取内容显示在模版上
        $('#' + option.tpl_box).empty().html(
            template(option.tpl_ele, result.data));
        permissonHandler();
        // 分页
        layui.use(['laypage', 'layer'], function () {
          var laypage = layui.laypage;
          laypage({
            cont: option.turnpage_ele,
            curr: curr || 1,
            pages: result.data.pages,
            skin: '#457fe6',
            skip: true,
            jump: function (obj, first) {
              var num = $('#' + option.page_ele + ' select').val()
              if (!first) {
                file.showDataByPage(option, obj.curr, num, searchKey, startDate,
                    endDate, companyCode, provinceCode, cityCode, countyCode);
              }
            }
          });
        });
      }
      else if (result.code == 9999) {
        layer.msg(result.msg, {time: 1000});
        wzERP.Common.TimeoutLogin();
        return false;
      }
    })
  },
  //渲染客户数据
  renderData: function (_option) {
    /*Arg Guide
     @ _option.search_ele 搜索表单id
     @ _option.searchkey tbody 搜索内容id
     @ _option.query_ele  查询按钮id
     @ _option.page_ele  选择页数id
     @ _option.tpl_box 模版盒子id
     @ _option.tpl_ele  模版渲染引擎id
     @ _option.turnpage_ele  分页id
     @ _option.customerType  客户类型(0:企业客户，1：个体客户，2：其他组织)
     */
    //默认第一页
    file.showDataByPage(_option, 1);
    // 每页显示条数
    $('#' + _option.page_ele).on('click', function () {
      var page = $('.ui.tab.active .layui-laypage-skip').val();
      // 获取表单序列属性对象
      var obj = formSerializeToObj(_option.search_ele);
      //获取当前每页应该显示条数
      var num = $('#' + _option.page_ele + ' select').val();
      //获取搜索框内容
      var searchKey = $('#' + _option.searchkey).val();
      //获取分割好的起止时间
      var startDate = obj.startDate;
      var endDate = obj.endDate;
      //获取公司编码
      var companyCode = obj.companyCode;
      //获取地址code
      var cityData = wzERP.Common.getCityData('#' + _option.city_ele);
      if (cityData) {
        var provinceCode = cityData[1].value;
        var cityCode = cityData[2].value;
        var countyCode = cityData[3].value;
      }
      //获取搜索内容
      file.showDataByPage(_option, page, num, searchKey, startDate, endDate,
          companyCode, provinceCode, cityCode, countyCode)
    })
    //查询业务
    $('#' + _option.query_ele).on('click', function () {
      // 获取表单序列属性对象
      var obj = formSerializeToObj(_option.search_ele);
      //获取当前每页应该显示条数
      var num = $('#' + _option.page_ele + ' select').val();
      //获取搜索框内容
      var searchKey = $('#' + _option.searchkey).val();
      //获取分割好的起止时间
      var startDate = obj.startDate;
      var endDate = obj.endDate;
      //获取所属公司编码
      var companyCode = obj.companyCode;
      //获取地址code
      var cityData = wzERP.Common.getCityData('#' + _option.city_ele);
      if (cityData) {
        var provinceCode = cityData[1].value;
        var cityCode = cityData[2].value;
        var countyCode = cityData[3].value;
      }
      //获取搜索内容
      file.showDataByPage(_option, 1, num, searchKey, startDate, endDate,
          companyCode, provinceCode, cityCode, countyCode)
      return false;
    })
  },
  //模态框步骤响应（上下步保存）（企业客户）
  stepResponseEnterprise: function (id) {
    /*Arg Guide
     @ id 模态框id
     */
    var self = this;
    var $modal = $('#' + id);//获取模态框
    var $tabHeader = $modal.find('.ui.tabular.menu .item');//获取tab头
    var $tab = $modal.find('.ui.tab');//获取tab
    var index_tab = $modal.find('.ui.tab.active').index() - 1;//获取当前tab的索引
    var $button_prev = $modal.find('.actions .prev');//获取上一步按钮
    var $button_next = $modal.find('.actions .savenext');//获取保存并下一步按钮
    var form_ele = '#' + id + ' .file-verifier';//获取要验证的表单

    var clientId;//声明客户id
    var canNextStep = true;//声明步骤权限

    actFromTabIndex(index_tab);//初始化按钮状态
    $modal.find('.ui.tab.active').scrollTop(0);//滚动到顶部

    /*---首页调用数据词典--S---*/
    //企业状态
    $.get(
        '/finance/erpAccountReceivable/querydictionDetailListByCode?code=enterpriseAppearance',
        function (result) {
          var $options = '<option value="">请选择</option>';
          if (result.code == 0) {
            var _data = result.data;
            _data.forEach(function (val) {
              $options += '<option value="' + val.id + '">' + val.name
                  + '</option>';
            })
          }
          else if (result.code == 9999) {
            layer.msg(result.msg, {time: 1000});
            wzERP.Common.TimeoutLogin();
            return false;
          }
          $modal.find('#enterpriseStatusCodeId').empty().append($options);
        });
    //企业性质
    $.get(
        '/finance/erpAccountReceivable/querydictionDetailListByCode?code=entrepreneurial',
        function (result) {
          var $options = '<option value="">请选择</option>';
          if (result.code == 0) {
            var _data = result.data;
            _data.forEach(function (val) {
              $options += '<option value="' + val.id + '">' + val.name
                  + '</option>';
            })
          }
          else if (result.code == 9999) {
            layer.msg(result.msg, {time: 1000});
            wzERP.Common.TimeoutLogin();
            return false;
          }
          $modal.find('#enterpriseNatureCodeId').empty().append($options);
        });
    //行业
    $.get(
        '/finance/erpAccountReceivable/querydictionDetailListByCode?code=industry',
        function (result) {
          var $options = '<option value="">请选择</option>';
          if (result.code == 0) {
            var _data = result.data;
            _data.forEach(function (val) {
              $options += '<option value="' + val.id + '">' + val.name
                  + '</option>';
            })
          }
          else if (result.code == 9999) {
            layer.msg(result.msg, {time: 1000});
            wzERP.Common.TimeoutLogin();
            return false;
          }
          $modal.find('#industryCodeId').empty().append($options);
        });
    /*---首页调用数据词典--E---*/

    //保存下一步操作
    $modal.find('.savenext').off('click').click(function () {
      if (!canNextStep) {  //是否能下一步
        return false;
      }
      canNextStep = false;
      //获取表单
      var form_ele = '#' + id + ' .ui.tab.active .file-verifier';
      //表单验证

      if (index_tab == 0 && !!self.checkform(form_ele)) {//第一页验证必填项

        //location判断
        file.checkLocation(form_ele);
        /*--------错误提示和位置处理------S------*/
        var firstError = $(form_ele).find('.ui.field.error').eq(0);//获取第一个错误
        var firstErrorMsg = firstError.find('.ui.basic.red.label').text();
        if (firstErrorMsg == '' && firstError.find('.city-picker-span').length
            > 0) {
          firstErrorMsg = '省市区地址请全选!'
        }
        //获取第一个报error相对顶部的距离
        var curActive = $modal.find('.ui.tab.active');
        var topToWindow = firstError.offset().top;
        var scrollBoxToWindow = curActive.offset().top;
        var scrollLength = curActive.scrollTop();
        var verticalShift = topToWindow + scrollLength - scrollBoxToWindow;
        //滚动到error的位置
        curActive.scrollTop(verticalShift - 8);
        //获取error提示信息
        layer.msg(firstErrorMsg, {icon: 2});
        /*--------错误提示和位置处理------E------*/

        canNextStep = true;
        return false;
      }
      //ajax保存当前页
      var obj = formSerializeToObj(form_ele);

      //根据当前页执行函数
      switch (index_tab) {
        case 0:
          var canMove = handleEnterpriseData();//企业资料处理
          if (!canMove) {
            return false
          }//操作有误无法下一步
          break;
        case 1:
          handleContact();//联系方式处理
          break;
        case 2:
          handleInvoice();//发票抬头处理
          break;
        default:
          return false;
      }

      //跳转下一页
      index_tab++;
      actFromTabIndex(index_tab);
      showTab(index_tab);

      //跳转步骤处理
      //企业资料处理
      function handleEnterpriseData() {
        //form提交前的name处理--Start
        //(注册资本单位转为分)
        var registeredCapital = $modal.find(
            '.basic-info input[name="registeredCapitalValidate"]').val();
        var unit = 6;//万元转分
        var registeredCapital = registeredCapital * Math.pow(10, unit);
        $modal.find('.basic-info input[name="registeredCapital"]').val(
            registeredCapital);
        //form提交前的name处理--End

        //form提交前保存客户标签
        var clientTags = [], canApprove = true;
        var tagItem = $('#' + id + ' .cus-tags-box .tag-item');
        if (tagItem.length > 0) {
          tagItem.each(function () {
            var tagVal = $(this).find('input').val();
            var tagId = $(this).find('input').data('id');
            canApprove = $.trim(tagVal) == '' ? false : true;
            clientTags.push({
              id: tagId,
              value: tagVal
            });
          })
        }
        if (!canApprove) {
          layer.msg('客户标签不能留空!', {icon: 5});
          canNextStep = true;
          return false;//有空标签不允许通过
        }

        //处理citycode
        var cityData = wzERP.Common.getCityData('#' + id + ' #city');
        var hasAllData = true;
        //是否全选判断
        if (!cityData) {
          hasAllData = false;
        } else {
          for (var i = 0; i < cityData.length; i++) {
            if (cityData[i].value == undefined) {
              hasAllData = false;
            }
          }
        }
        if (hasAllData) {
          $("#" + id + " #provinceCode").val(cityData[1].value);
          $("#" + id + " #countyCode").val(cityData[3].value);
          $("#" + id + " #cityCode").val(cityData[2].value);
        } else {
          //省市区没全选情况下
          layer.msg('省市区地址请全选!', {icon: 5});
          //定位到顶部
          var curActive = $modal.find('.ui.tab.active');
          curActive.scrollTop(0);
          //标红error
          curActive.find('.city-picker-input').parents(
              '.ui.input.field').addClass('error');

          canNextStep = true;
          return false;
        }
        //转数字
        var formObj = formSerializeToObj(form_ele);
        if (formObj['registeredCapital']) {
          formObj['registeredCapital'] = parseInt(formObj['registeredCapital']);
        }
        formObj['customerType'] = 0;//企业客户
        //更新添加id
        if (clientId) {
          formObj['id'] = clientId;
        }
        $.ajax({
          type: "POST",
          url: '/customer/addOrUpdate',
          /*contentType: "application/json",
           dataType: "json",
           data: JSON.stringify(formObj),*/
          data: formObj,
          success: function (result) {
            if (result.code == 0) {
              clientId = result.data;
              $('#cust').val(clientId);//保存客户id
              layer.msg('保存成功!', {icon: 7});

              canNextStep = true;//后台返回可以下一步操作

              if (clientTags.length == 0) {
                return false
              }//没标签则不提交

              //获取客户id后批量上传客户标签
              var postArr = [];
              for (var i = 0; i < clientTags.length; i++) {
                postArr.push({
                  "custId": clientId,
                  "id": clientTags[i].id,
                  "labelName": clientTags[i].value
                })
              }
              if (postArr.length > 0) {
                $.ajax({
                  type: "POST",
                  url: self.interface.batchAddOrUpdate,
                  contentType: "application/json",
                  dataType: "json",
                  data: JSON.stringify(postArr),
                  success: function (data) {
                    console.log('客户标签上传', data.msg);
                  }
                });
              }
            }
            else if (result.code == 9999) {
              layer.msg(result.msg, {time: 1000});
              wzERP.Common.TimeoutLogin();
              return false;
            }
            else {
              layer.msg(result.msg, {icon: 5});
              canNextStep = true;
            }
          }
        })

        //查找当前客户的最近一条数据报表记录接口
        $.post(self.interface.findLastOneData, {cusId: clientId},
            function (result) {
              if (result.code == 0) {
                var data = result.data;
                console.log('返回最近一条数据报表记录', data);
                var renderData = file.handleDataToRender(data);
                var obj = {
                  'dataTable': renderData
                }
                console.log(renderData);
                //模版渲染
                $('#' + id + ' #modal_datatable').empty().html(
                    template('modalTpl_datatable', obj));
                //渲染后要启动表单验证
                file.verifier('.data-table-form');
                permissonHandler();
              }
              else if (result.code == 9999) {
                layer.msg(result.msg, {time: 1000});
                wzERP.Common.TimeoutLogin();
                return false;
              }
            });
        return true;
      }

      //联系方式处理
      function handleContact() {
        canNextStep = true;
      }

      //发票抬头处理
      function handleInvoice() {
        canNextStep = true;
      }
    });

    //上一步操作
    $modal.find('.actions .prev').off('click').click(function () {
      index_tab--;
      actFromTabIndex(index_tab);
      showTab(index_tab);
      if (index_tab == 0 && clientId) {//企业客户标签更新处理
        $.get('/customer/erpCustomerLabel/findCusIdAll', {id: clientId},
            function (result) {
              if (result.code == 0) {
                var tags_data = result.data;
                var tags_html = '';
                tags_data.forEach(function (item) {
                  tags_html += '<div class="tag-item editing"><div class="ui mini icon input"><input type="text" placeholder="标签" name="tag" data-id="'
                      + item.id + '" value="' + item.labelName
                      + '"></div><i class="remove circle icon"></i></div>'
                });
                $('#' + id + ' .cus-tags-box div').remove('.tag-item');
                $(tags_html).insertBefore(
                    '#' + id + ' .cus-tags-box .add-area');
              }
              else if (result.code == 9999) {
                layer.msg(result.msg, {time: 1000});
                wzERP.Common.TimeoutLogin();
                return false;
              }
              else {
                layer.msg('获取客户标签失败!', {icon: 5});
              }
            })
      }
    });

    //根据tab索引显示隐藏按钮
    function actFromTabIndex(i) {
      /*Arg Guide
       @ i 要显示的tab索引
       */
      if (typeof i == 'number') {
        //显示隐藏上一步
        i == 0 ? $button_prev.hide() : $button_prev.show();
        //显示隐藏保存按钮
        i == ($tab.length - 1) ? $button_next.hide() : $button_next.show();
        //根据保存状况动态改变
        var saveState = $tab.eq(i).data('save');
        saveState == true ? $button_next.text('下一步') : $button_next.text(
            '保存并下一步');
      }
    }

    //显示指定的tab
    function showTab(i) {
      /*Arg Guide
       @ i 要显示的tab索引
       */
      $tabHeader.eq(i).addClass('active').siblings('.item').removeClass(
          'active');
      $tab.eq(i).addClass('active').siblings('.ui.tab').removeClass('active');
      $modal.find('.ui.tab.active').scrollTop(0);//滚动到顶部
    }
  },
  //模态框步骤响应（上下步保存）（个人客户）
  stepResponsePersonal: function (id) {
    /*Arg Guide
     @ id 模态框id
     */
    var self = this;
    var $modal = $('#' + id);//获取模态框
    var $tabHeader = $modal.find('.ui.tabular.menu .item');//获取tab头
    var $tab = $modal.find('.ui.tab');//获取tab
    var index_tab = $modal.find('.ui.tab.active').index() - 1;//获取当前tab的索引
    var $button_prev = $modal.find('.actions .prev');//获取上一步按钮
    var $button_next = $modal.find('.actions .savenext');//获取保存并下一步按钮
    var form_ele = '#' + id + ' .file-verifier';//获取要验证的表单

    var clientId;//声明客户id
    var individualId;//声明个体表id
    var canNextStep = true;//声明步骤权限

    actFromTabIndex(index_tab);//初始化按钮状态
    $modal.find('.ui.tab.active').scrollTop(0);//滚动到顶部

    //保存下一步操作
    $modal.find('.savenext').off('click').click(function () {
      if (!canNextStep) {  //是否能下一步
        return false;
      }
      canNextStep = false;
      //获取表单
      var form_ele = '#' + id + ' .ui.tab.active .file-verifier';
      //表单验证

      if (index_tab == 0 && !!self.checkform(form_ele)) {//第一页验证必填项

        //location判断
        file.checkLocation(form_ele);
        /*--------错误提示和位置处理------S------*/
        var firstError = $(form_ele).find('.ui.field.error').eq(0);//获取第一个错误
        var firstErrorMsg = firstError.find('.ui.basic.red.label').text();
        if (firstErrorMsg == '' && firstError.find('.city-picker-span').length
            > 0) {
          firstErrorMsg = '省市区地址请全选!'
        }
        //获取第一个报error相对顶部的距离
        var curActive = $modal.find('.ui.tab.active');
        var topToWindow = firstError.offset().top;
        var scrollBoxToWindow = curActive.offset().top;
        var scrollLength = curActive.scrollTop();
        var verticalShift = topToWindow + scrollLength - scrollBoxToWindow;
        //滚动到error的位置
        curActive.scrollTop(verticalShift - 8);
        //获取error提示信息
        layer.msg(firstErrorMsg, {icon: 2});
        /*--------错误提示和位置处理------E------*/

        canNextStep = true;
        return false;
      }
      //ajax保存当前页
      var obj = formSerializeToObj(form_ele);

      //根据当前页执行函数
      switch (index_tab) {
        case 0:
          var canMove = handlePersonalData();//企业资料处理
          if (!canMove) {
            return false
          }//操作有误无法下一步
          break;
        case 1:
          handleContact();//联系方式处理
          break;
        case 2:
          handleInvoice();//发票抬头处理
          break;
        default:
          return false;
      }

      //跳转下一页
      index_tab++;
      actFromTabIndex(index_tab);
      showTab(index_tab);

      //跳转步骤处理
      //个人资料处理
      function handlePersonalData() {
        //form提交前的name处理--Start
        //处理citycode
        var cityData = wzERP.Common.getCityData('#' + id + ' #city');
        var hasAllData = true;
        //是否全选判断
        if (!cityData) {
          hasAllData = false;
        } else {
          for (var i = 0; i < cityData.length; i++) {
            if (cityData[i].value == undefined) {
              hasAllData = false;
            }
          }
        }
        if (hasAllData) {
          $("#" + id + " #provinceCode").val(cityData[1].value);
          $("#" + id + " #countyCode").val(cityData[3].value);
          $("#" + id + " #cityCode").val(cityData[2].value);
        } else {
          //省市区没全选情况下
          layer.msg('省市区地址请全选!', {icon: 5});
          //定位到顶部
          var curActive = $modal.find('.ui.tab.active');
          curActive.scrollTop(0);
          //标红error
          curActive.find('.city-picker-input').parents(
              '.ui.input.field').addClass('error');

          canNextStep = true;
          return false;
        }
        var formObj = formSerializeToObj(form_ele);
        formObj['customerType'] = 1;//个体客户
        //更新添加id
        if (clientId) {
          formObj['id'] = clientId;
          formObj['individualId'] = individualId;
        }
        $.ajax({
          type: "POST",
          url: '/customer/erpIndividualCustomer/addOrUpdate',
          data: formObj,
          success: function (result) {
            if (result.code == 0) {
              clientId = result.data.id ? result.data.id : result.data;
              individualId = result.data.individualId ? result.data.individualId
                  : result.data;
              $('#cust').val(clientId);//保存客户id
              layer.msg('保存成功!', {icon: 7});
              canNextStep = true;//后台返回可以下一步操作
            } else {
              layer.msg(result.msg, {icon: 5});
              canNextStep = true;
            }
          }
        })
        return true;
      }

      //联系方式处理
      function handleContact() {
        canNextStep = true;
      }

      //发票抬头处理
      function handleInvoice() {
        canNextStep = true;
      }
    });

    //上一步操作
    $modal.find('.actions .prev').off('click').click(function () {

      index_tab--;
      actFromTabIndex(index_tab);
      showTab(index_tab);

    });

    //根据tab索引显示隐藏按钮
    function actFromTabIndex(i) {
      /*Arg Guide
       @ i 要显示的tab索引
       */
      if (typeof i == 'number') {
        //显示隐藏上一步
        i == 0 ? $button_prev.hide() : $button_prev.show();
        //显示隐藏保存按钮
        i == ($tab.length - 1) ? $button_next.hide() : $button_next.show();
        //根据保存状况动态改变
        var saveState = $tab.eq(i).data('save');
        saveState == true ? $button_next.text('下一步') : $button_next.text(
            '保存并下一步');
      }
    }

    //显示指定的tab
    function showTab(i) {
      /*Arg Guide
       @ i 要显示的tab索引
       */
      $tabHeader.eq(i).addClass('active').siblings('.item').removeClass(
          'active');
      $tab.eq(i).addClass('active').siblings('.ui.tab').removeClass('active');
      $modal.find('.ui.tab.active').scrollTop(0);//滚动到顶部
    }
  },
  //模态框步骤响应（上下步保存）（其它组织客户）
  stepResponseOther: function (id) {
    /*Arg Guide
     @ id 模态框id
     */
    var self = this;
    var $modal = $('#' + id);//获取模态框
    var $tabHeader = $modal.find('.ui.tabular.menu .item');//获取tab头
    var $tab = $modal.find('.ui.tab');//获取tab
    var index_tab = $modal.find('.ui.tab.active').index() - 1;//获取当前tab的索引
    var $button_prev = $modal.find('.actions .prev');//获取上一步按钮
    var $button_next = $modal.find('.actions .savenext');//获取保存并下一步按钮
    var form_ele = '#' + id + ' .file-verifier';//获取要验证的表单

    var clientId;//声明客户id
    var canNextStep = true;//声明步骤权限

    actFromTabIndex(index_tab);//初始化按钮状态
    $modal.find('.ui.tab.active').scrollTop(0);//滚动到顶部

    /*---首页调用数据词典--S---*/
    //企业状态
    $.get(
        '/finance/erpAccountReceivable/querydictionDetailListByCode?code=enterpriseAppearance',
        function (result) {
          var $options = '<option value="">请选择</option>';
          if (result.code == 0) {
            var _data = result.data;
            _data.forEach(function (val) {
              $options += '<option value="' + val.id + '">' + val.name
                  + '</option>';
            })
          }
          else if (result.code == 9999) {
            layer.msg(result.msg, {time: 1000});
            wzERP.Common.TimeoutLogin();
            return false;
          }
          $modal.find('#enterpriseStatusCodeId').empty().append($options);
        });
    //组织类别
    $.get(
        '/finance/erpAccountReceivable/querydictionDetailListByCode?code=organizationCategory',
        function (result) {
          var $options = '<option value="">请选择</option>';
          if (result.code == 0) {
            var _data = result.data;
            _data.forEach(function (val) {
              $options += '<option value="' + val.id + '">' + val.name
                  + '</option>';
            })
          }
          else if (result.code == 9999) {
            layer.msg(result.msg, {time: 1000});
            wzERP.Common.TimeoutLogin();
            return false;
          }
          $modal.find('#organizationCategoryCodeId').empty().append($options);
        });
    /*---首页调用数据词典--E---*/

    //保存下一步操作
    $modal.find('.savenext').off('click').click(function () {
      if (!canNextStep) {  //是否能下一步
        return false;
      }
      canNextStep = false;
      //获取表单
      var form_ele = '#' + id + ' .ui.tab.active .file-verifier';
      //表单验证

      if (index_tab == 0 && !!self.checkform(form_ele)) {//第一页验证必填项

        //location判断
        file.checkLocation(form_ele);
        /*--------错误提示和位置处理------S------*/
        var firstError = $(form_ele).find('.ui.field.error').eq(0);//获取第一个错误
        var firstErrorMsg = firstError.find('.ui.basic.red.label').text();
        if (firstErrorMsg == '' && firstError.find('.city-picker-span').length
            > 0) {
          firstErrorMsg = '省市区地址请全选!'
        }
        //获取第一个报error相对顶部的距离
        var curActive = $modal.find('.ui.tab.active');
        var topToWindow = firstError.offset().top;
        var scrollBoxToWindow = curActive.offset().top;
        var scrollLength = curActive.scrollTop();
        var verticalShift = topToWindow + scrollLength - scrollBoxToWindow;
        //滚动到error的位置
        curActive.scrollTop(verticalShift - 8);
        //获取error提示信息
        layer.msg(firstErrorMsg, {icon: 2});
        /*--------错误提示和位置处理------E------*/

        canNextStep = true;
        return false;
      }
      //ajax保存当前页
      var obj = formSerializeToObj(form_ele);

      //根据当前页执行函数
      switch (index_tab) {
        case 0:
          var canMove = handleOtherData();//企业资料处理
          if (!canMove) {
            return false
          }//操作有误无法下一步
          break;
        case 1:
          handleContact();//联系方式处理
          break;
        case 2:
          handleInvoice();//发票抬头处理
          break;
        default:
          return false;
      }

      //跳转下一页
      index_tab++;
      actFromTabIndex(index_tab);
      showTab(index_tab);

      //跳转步骤处理
      //其它组织资料处理
      function handleOtherData() {
        //处理citycode
        var cityData = wzERP.Common.getCityData('#' + id + ' #city');
        var hasAllData = true;
        //是否全选判断
        if (!cityData) {
          hasAllData = false;
        } else {
          for (var i = 0; i < cityData.length; i++) {
            if (cityData[i].value == undefined) {
              hasAllData = false;
            }
          }
        }
        if (hasAllData) {
          $("#" + id + " #provinceCode").val(cityData[1].value);
          $("#" + id + " #countyCode").val(cityData[3].value);
          $("#" + id + " #cityCode").val(cityData[2].value);
        } else {
          //省市区没全选情况下
          layer.msg('省市区地址请全选!', {icon: 5});
          //定位到顶部
          var curActive = $modal.find('.ui.tab.active');
          curActive.scrollTop(0);
          //标红error
          curActive.find('.city-picker-input').parents(
              '.ui.input.field').addClass('error');

          canNextStep = true;
          return false;
        }
        var formObj = formSerializeToObj(form_ele);
        formObj['customerType'] = 2;//其它组织客户
        console.info(formObj);
        $.ajax({
          type: "POST",
          url: '/customer/addOrUpdate',
          data: formObj,
          success: function (result) {
            if (result.code == 0) {
              clientId = result.data;
              $('#cust').val(clientId);//保存客户id
              hasSaveOther = true;//防止重复保存
              layer.msg('保存成功!', {icon: 7});
              canNextStep = true;//后台返回可以下一步操作
            }
            else if (result.code == 9999) {
              layer.msg(result.msg, {time: 1000});
              wzERP.Common.TimeoutLogin();
              return false;
            }
            else {
              layer.msg(result.msg, {icon: 5});
              canNextStep = true;
            }
          }
        });
        return true;
      }

      //联系方式处理
      function handleContact() {
        canNextStep = true;

      }

      //发票抬头处理
      function handleInvoice() {
        canNextStep = true;
      }
    });

    //上一步操作
    $modal.find('.actions .prev').off('click').click(function () {

      index_tab--;
      actFromTabIndex(index_tab);
      showTab(index_tab);

    });

    //根据tab索引显示隐藏按钮
    function actFromTabIndex(i) {
      /*Arg Guide
       @ i 要显示的tab索引
       */
      if (typeof i == 'number') {
        //显示隐藏上一步
        i == 0 ? $button_prev.hide() : $button_prev.show();
        //显示隐藏保存按钮
        i == ($tab.length - 1) ? $button_next.hide() : $button_next.show();
        //根据保存状况动态改变
        var saveState = $tab.eq(i).data('save');
        saveState == true ? $button_next.text('下一步') : $button_next.text(
            '保存并下一步');
      }
    }

    //显示指定的tab
    function showTab(i) {
      /*Arg Guide
       @ i 要显示的tab索引
       */
      $tabHeader.eq(i).addClass('active').siblings('.item').removeClass(
          'active');
      $tab.eq(i).addClass('active').siblings('.ui.tab').removeClass('active');
      $modal.find('.ui.tab.active').scrollTop(0);//滚动到顶部
    }
  },
  //表单验证出口
  checkform: function (ele) {
    /*Arg Guide
     @ ele 要验证的表单
     */
    $(ele).form('submit');
    return $(ele).hasClass('error');
  },
  //验证citypicker
  checkLocation: function (ele) {
    var locationInput;
    var locationBox;
    if ($(ele).is('.city-picker-input')) {
      locationInput = $(ele);
    } else {
      locationInput = $(ele).find('.city-picker-input');
    }
    locationBox = locationInput.parent('.field');
    if (locationBox.find('.city-picker-span .select-item').length == 3) {
      locationBox.removeClass('error')
      return true;
    } else {
      locationBox.addClass('error')
      return false;
    }
  },
  //上传文件
  uploadFile: function (body_ele, ele_trigger, ele_form, file_type) {
    /*Arg Guide
     @ trigger_id 触发按钮id(label)
     @ form_id 表单提交的id
     @ file_type 0:图片 1:pdf
     */
    if (file_type == 0) {
      $(body_ele).on('click', ele_trigger, function () {
        var $self = $(this);
        var input_name = $(this).attr('for');
        var $input_file = $('#' + input_name); //获取上传文件的input
        var maxSize = 2 * 1024 * 1024;//最大容量
        $input_file.off('change').change(function () {
          var $iVal = $input_file.val();
          if ($iVal) {
            if (!($iVal.endsWith('jpg') || $iVal.endsWith('jpeg')
                || $iVal.endsWith('png') || $iVal.endsWith('gif')
                || $iVal.endsWith('bmp'))) {
              layer.msg('请上传图片格式', {icon: 5})
            } else {
              if ($input_file[0].files[0].size > maxSize) {
                layer.msg('上传图片不能超过2M', {icon: 5});
                return false;
              }
              $(ele_form).ajaxSubmit({
                type: 'POST',
                success: function (result) {
                  if (result.code == 0) {
                    var filePath = result.data.filePath;
                    var fileName = result.data.fileName;
                    var img = document.createElement('img');
                    img.src = filePath;
                    img.name = fileName;
                    $self.siblings('input[type="hidden"]').val(filePath);
                    $self.parent().find('img').hide();//隐藏上传提示图片
                    $self.parent().append($(img));//显示返回的图片
                    $self.parent().addClass('hover-show');
                    layer.msg('上传成功', {time: 1000});
                    $self.parent().find('.zoom-label').off('click').click(
                        function () {
                          file.openBigPic('#bigPicShowLayer', filePath);
                        });
                    $input_file.val('');
                  }
                }
              });
            }
          }
        })
      })
    } else if (file_type == 1) {
      $(body_ele).on('click', ele_trigger, function () {
        var $self = $(this);
        var input_name = $(this).attr('for');
        var $input_file = $('#' + input_name); //获取上传文件的input
        var maxSize = 2 * 1024 * 1024;//最大容量
        $input_file.off('change').change(function () {
          var $iVal = $input_file.val();
          if ($iVal) {
            if (!$iVal.endsWith('pdf')) {
              layer.msg('请上传pdf格式', {icon: 5})
            } else {
              if ($input_file[0].files[0].size > maxSize) {
                layer.msg('上传pdf不能超过2M', {icon: 5});
                return false;
              }
              $(ele_form).ajaxSubmit({
                type: 'POST',
                success: function (result) {
                  if (result.code == 0) {
                    var filePath = result.data.filePath;
                    // var fileName = result.data.fileName;
                    var img = document.createElement('img');
                    img.className = 'pdficon';
                    $self.siblings('input[type="hidden"]').val(filePath);
                    $self.parent().find('img').hide();//隐藏上传提示图片
                    $self.parent().append($(img));//显示返回的图片
                    $self.parent().addClass('hover-show');
                    layer.msg('上传成功', {time: 1000});
                    $self.parent().find('.zoom-label').off('click').click(
                        function () {
                          window.open(filePath);
                        });
                    $input_file.val('');
                  }
                  else if (result.code == 9999) {
                    layer.msg(result.msg, {time: 1000});
                    wzERP.Common.TimeoutLogin();
                    return false;
                  }
                }
              });
            }
          }
        })
      })
    }
  },
  //上传pdf
  uploadFilePdf: function (body_ele, ele_trigger, ele_form) {
    /*Arg Guide
     @ trigger_id 触发按钮id(label)
     @ form_id 表单提交的id
     */
    $(body_ele).on('click', ele_trigger, function () {
      var $self = $(this);
      var input_name = $(this).attr('for');
      var $input_file = $('#' + input_name); //获取上传文件的input
      var maxSize = 2 * 1024 * 1024;//最大容量
      $input_file.off('change').change(function () {
        var $iVal = $input_file.val();
        if ($iVal) {
          if (!$iVal.endsWith('pdf')) {
            layer.msg('请上传pdf格式', {icon: 5})
          } else {
            if ($input_file[0].files[0].size > maxSize) {
              layer.msg('上传pdf不能超过2M', {icon: 5});
              return false;
            }
            $(ele_form).ajaxSubmit({
              type: 'POST',
              success: function (result) {
                if (result.code == 0) {
                  var filePath = result.data.filePath;
                  var fileName = result.data.fileName;
                  $self.text('重新上传证明');
                  $self.siblings('a').remove('.seePdf')
                  $self.parent().prepend(
                      '<a class="ui blue button seePdf" href="' + filePath
                      + '" style="display:inline-block" target="_blank">预览</a>');
                  $self.siblings('input[type="hidden"]').val(filePath);
                  $input_file.val('');
                  layer.msg('上传成功!', {icon: 7});
                }
                else if (result.code == 9999) {
                  layer.msg(result.msg, {time: 1000});
                  wzERP.Common.TimeoutLogin();
                  return false;
                }
              }
            });
          }
        }
      })
    })
  }
}

//序列化表单值转为对象
function formSerializeToObj(id) {
  /*Arg Guide
   @ id 表单id
   */
  // 获取表单序列值
  var content;
  if (typeof id == 'string' && id[0] == '.') {
    content = $(id).serialize();
  } else if (typeof id == 'string' && id[0] == '#') {
    content = $(id).serialize();
  } else {
    content = $("#" + id).serialize();
  }
  content = decodeURIComponent(content, true);
  //使用方法分割取出
  var contentS = content.split('&')
  var obj = {}
  for (var i = 0; i < contentS.length; i++) {
    var con = contentS[i].toString()
    var son = con.split('=')
    obj[son[0]] = son[1]
  }
  return obj
}

/*
 * 检测对象是否是空对象(不包含任何可读属性)。
 * 方法既检测对象本身的属性，也检测从原型继承的属性(因此没有使hasOwnProperty)。
 */
function isObjectEmpty(obj) {
  for (var name in obj) {
    return false;
  }
  return true;
};

//提交ajax按需提交操作
file.saveAjaxHandle = function (_obj) {
  /*Arg Guide
   @ _obj.formdata:提交form的ID
   @ _obj.url:接口地址
   @ _obj.extendObj: 继承对象
   @ _obj.successFn  成功处理回调
   @ _obj.errorFn  错误处理回调
   */
  var param = _obj.param, //json数据
      submitUrl = _obj.url;//接口地址
  if (Array.isArray(_obj.extendObj)) {
    param = $.extend(param, _obj.extendObj);
  }
  $.ajax({
    type: "POST",
    url: submitUrl,
    contentType: "application/json",
    dataType: "json",
    data: JSON.stringify(param),
    success: function (data) {
      if (data.code == 9999) {
        layer.msg(data.msg, {time: 1000});
        wzERP.Common.TimeoutLogin();
        return false;
      }
      var resData = data.data;
      if (resData) {
        _obj.newId = resData.id;
      }
      switch (data.code) {
        case 0://成功
          layer.msg(data.msg, {icon: 7});
          if (_obj.successFn instanceof Function) {
            _obj.successFn();
          }
          break;
        case 1: //失败
          layer.msg(data.msg, {icon: 5});
          if (_obj.errorFn instanceof Function) {
            _obj.errorFn();
          }
          break;
        default: //默认
          layer.msg(data.msg, {icon: 2});
          if (_obj.errorFn instanceof Function) {
            _obj.errorFn();
          }
      }
    }
  });
};

//数据列表处理为渲染格式
file.handleDataToRender = function (_data) {
  /*Arg Guide
   @_data: 后台返回的data
   */
  var now = new Date().getFullYear();
  var defaultYears = [now - 1, now - 2, now - 3]; //默认显示前三年
  var renderData = [
    {
      'year': now - 1,
      'edit': true
    },
    {
      'year': now - 2,
      'edit': true
    },
    {
      'year': now - 3,
      'edit': true
    }
  ];
  if (_data == null || _data.length == 0) {
    return renderData;
  } else if (_data.length > 1) {
    //处理多条数据的情况下
    _data.forEach(function (value) {
      value['edit'] = false;
    });
    return _data;
  }
  var year = _data.year - 0;
  //处理年限
  var outputYears = [];
  if (now - 3 > year) {
    outputYears = defaultYears.concat(year);
    //处理多列的情况下
    renderData.push({
      'year': year,
      'edit': true
    })
  } else {
    outputYears = defaultYears;
  }
  //获取展示列的索引
  var viewIndex = outputYears.indexOf(year);
  renderData[viewIndex]['edit'] = false;
  for (var i in _data) {
    renderData[viewIndex][i] = _data[i]
  }
  //年限转为string格式
  renderData.forEach(function (item) {
    item['year'] = item['year'] + '';
  })
  return renderData;
}

//表单批量上传
file.batchPost = function (_selector, _url, _custId) {
  /*Arg Guide
   @_selector: 对象选择器
   @_url: 接口地址
   @_custId: 客户id
   */

  var $formData = $(_selector);
  var lengthInputColumns = $formData.find('tr th').length - 1;
  var dataTableArr = [];
  for (var i = 0; i < lengthInputColumns; i++) {
    var itemObj = {};
    $formData.find('tr').each(function () {
      var $input = $(this).find('td:nth-child(' + (i + 2) + ')').find('input');
      var $keyTxt = $(this).find('td:first-child').text();//字符
      if ($input.length > 0 && !$input.attr('readonly')) {
        var key = $input.attr('name');
        var value = $input.val();
        if ($keyTxt.indexOf('万元') > 0) {
          var unit = 6;//万元转分
          itemObj[key] = value * Math.pow(10, unit);
        } else {
          itemObj[key] = value;
        }
        //年份
        itemObj['year'] = $formData.find(
            'tr th:nth-child(' + (i + 2) + ')').text().replace('年', '');
        //赋予客户id
        itemObj['custId'] = _custId;
      }
    });
    if (!isObjectEmpty(itemObj)) {
      dataTableArr.push(itemObj)
    }
  }
  console.log(dataTableArr);
  console.log(JSON.stringify(dataTableArr));
  $.ajax({
    type: "POST",
    url: _url,
    contentType: "application/json",
    dataType: "json",
    data: JSON.stringify(dataTableArr),
    success: function (data) {
      if (data.code == 9999) {
        layer.msg(data.msg, {time: 1000});
        wzERP.Common.TimeoutLogin();
        return false;
      }
      console.log('表单批量上传', data.msg);
    }
  });
}

//表单验证器
file.verifier = function (_selector) {
  /*Arg Guide
   @_selector: 对象选择器
   */
  $(_selector).form({
    on: 'blur',
    inline: true,
    transition: 'fade',
    fields: {
      //公司名称
      companyName: {
        identifier: 'companyName',
        rules: [{
          type: 'empty',
          prompt: '请输入名称'
        },
          {
            type: 'regExp[/^.{0,50}$/]',
            prompt: '(公司名称)限制50字'
          }]
      },
      //联系电话
      contactNumber: {
        identifier: 'contactNumber',
        rules: [{
          type: 'empty',
          prompt: '请输入联系电话'
        },
          {
            type: 'regExp[/^[0-9-]{0,20}$/]',
            prompt: '(联系电话)只能输入数字及-，字数限制20字'
          }]
      },
      //手机号码
      phoneNumber: {
        identifier: 'phoneNumber',
        rules: [{
          type: 'empty',
          prompt: '请输入联系电话'
        },
          {
            type: 'regExp[/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/]',
            prompt: '请输入正确的手机号码'
          }]
      },
      //联系人类型
      contactType: {
        identifier: 'contactType',
        rules: [{
          type: 'empty',
          prompt: '请输入联系人类型'
        }]
      },
      //联系传真
      fax: {
        identifier: 'fax',
        rules: [{
          type: 'regExp[/^[0-9-]{0,20}$/]',
          prompt: '(联系传真)只能输入数字及-，字数限制20字'
        }]
      },
      //邮箱
      emailAddress: {
        identifier: 'emailAddress',
        rules: [{
          type: 'empty',
          prompt: '请输入邮箱地址'
        }, {
          type: 'regExp[/^([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+\\.[a-zA-Z]{2,3}$/]',
          prompt: '请输入正确的邮箱格式'
        }, {
          type: 'regExp[/^.{0,30}$/]',
          prompt: '限制30字'
        }]
      },
      //网址
      corporateLink: {
        identifier: 'corporateLink',
        optional: true,
        rules: [{
          type: 'regExp[/^.{0,30}$/]',
          prompt: '限制30字'
        }, {
          type: 'url',
          prompt: '请输入正确的网址格式'
        }]
      },
      //联系地址
      detailAddr: {
        identifier: 'detailAddr',
        rules: [{
          type: 'empty',
          prompt: '请输入联系地址'
        }, {
          type: 'regExp[/^.{0,50}$/]',
          prompt: '(联系地址)限制50字'
        }]
      },
      //统一信用代码证
      creditCode: {
        identifier: 'creditCode',
        optional: true,
        rules: [{
          type: 'regExp[/^[a-zA-Z0-9]{18}$/]',
          prompt: '(统一信用代码证)18位数字或字母'
        }]
      },
      //营业执照
      businessLicense: {
        identifier: 'businessLicense',
        optional: true,
        rules: [{
          type: 'regExp[/^[a-zA-Z0-9]{15,18}$/]',
          prompt: '(营业执照)限15-18位数字或字母'
        }]
      },
      //组织机构代码证
      organizationCode: {
        identifier: 'organizationCode',
        optional: true,
        rules: [{
          type: 'regExp[/^[a-zA-Z0-9]{9}$/]',
          prompt: '(组织机构代码证)9位数字或字母'
        }]
      },
      //税务登记证
      taxRegistrationCertificate: {
        identifier: 'taxRegistrationCertificate',
        optional: true,
        rules: [{
          type: 'regExp[/^[a-zA-Z0-9]{15}$/]',
          prompt: '(税务登记证)15位数字或字母'
        }]
      },
      //企业法人
      enterpriseLegalPerson: {
        identifier: 'enterpriseLegalPerson',
        optional: true,
        rules: [{
          type: 'regExp[/^.{0,20}$/]',
          prompt: '(企业法人)限制20字'
        }]
      },
      //法人身份证
      legalPersonCard: {
        identifier: 'legalPersonCard',
        optional: true,
        rules: [{
          type: 'regExp[/^[a-zA-Z0-9]{18}$/]',
          prompt: '(法人身份证)18位数字或字母'
        }]
      },
      //开户银行
      openAccountBank: {
        identifier: 'openAccountBank',
        optional: true,
        rules: [{
          type: 'regExp[/^.{0,20}$/]',
          prompt: '(开户银行)限制20字'
        }]
      },
      //银行账号
      accountBank: {
        identifier: 'accountBank',
        optional: true,
        rules: [{
          type: 'regExp[/^\\d{16,19}$/]',
          prompt: '(银行账号)限16到19位数字'
        }]
      },
      //注册资本
      registeredCapital: {
        identifier: 'registeredCapitalValidate',
        optional: true,
        rules: [{
          type: 'regExp[/^\\d+(?:\\.\\d{1,2})?$/]',
          prompt: '(注册资本)最多两位有效小数'
        }]
      },
      //注册地址
      registAddr: {
        identifier: 'registAddr',
        optional: true,
        rules: [{
          type: 'regExp[/^.{0,50}$/]',
          prompt: '(注册地址)限制50字'
        }]
      },
      //登记开关
      registAuthority: {
        identifier: 'registAuthority',
        optional: true,
        rules: [{
          type: 'regExp[/^.{0,50}$/]',
          prompt: '(登记开关)限制50字'
        }]
      },
      //英文名称
      englishName: {
        identifier: 'englishName',
        optional: true,
        rules: [{
          type: 'regExp[/^.{0,50}$/]',
          prompt: '(英文名称)限制50字'
        }]
      },
      //英文地址
      englishAddr: {
        identifier: 'englishAddr',
        optional: true,
        rules: [{
          type: 'regExp[/^.{0,50}$/]',
          prompt: '(英文地址)限制50字'
        }]
      },
      //邮编
      custPostCode: {
        identifier: 'custPostCode',
        optional: true,
        rules: [{
          type: 'regExp[/^\\d{0,10}$/]',
          prompt: '(邮编)限10位数字'
        }]
      },
      //经营场所
      placeBusiness: {
        identifier: 'placeBusiness',
        optional: true,
        rules: [{
          type: 'regExp[/^.{0,20}$/]',
          prompt: '(经营场所)限制20字'
        }]
      },
      //经营范围
      scopeBusiness: {
        identifier: 'scopeBusiness',
        rules: [{
          type: 'regExp[/^[^]{0,1000}$/]',
          prompt: '(经营范围)长度1000字以内'
        }]
      },
      //企业发展史
      corporateHistory: {
        identifier: 'corporateHistory',
        optional: true,
        rules: [{
          type: 'regExp[/^[^]{0,1000}$/]',
          prompt: '(企业发展史)长度1000字以内'
        }]
      },
      //经营理念
      managementIdea: {
        identifier: 'managementIdea',
        optional: true,
        rules: [{
          type: 'regExp[/^[^]{0,1000}$/]',
          prompt: '(经营理念)长度1000字以内'
        }]
      },
      //企业文化
      corporateCulture: {
        identifier: 'corporateCulture',
        optional: true,
        rules: [{
          type: 'regExp[/^[^]{0,1000}$/]',
          prompt: '(企业文化)长度1000字以内'
        }]
      },
      //数据报表
      //年营业收入(万元)
      annualOperatingIncome: {
        identifier: 'annualOperatingIncome',
        optional: true,
        rules: [{
          type: 'regExp[/^\\d+(?:\\.\\d{1,2})?$/]',
          prompt: '(年营业收入)最多两位有效小数'
        }]
      },
      //年销售收入(万元)
      annualSalesIncome: {
        identifier: 'annualSalesIncome',
        optional: true,
        rules: [{
          type: 'regExp[/^\\d+(?:\\.\\d{1,2})?$/]',
          prompt: '(年销售收入)最多两位有效小数'
        }]
      },
      //年产值(万元)
      annualOutputValue: {
        identifier: 'annualOutputValue',
        optional: true,
        rules: [{
          type: 'regExp[/^\\d+(?:\\.\\d{1,2})?$/]',
          prompt: '(年产值)最多两位有效小数'
        }]
      },
      //利润(万元)
      profit: {
        identifier: 'profit',
        optional: true,
        rules: [{
          type: 'regExp[/^\\d+(?:\\.\\d{1,2})?$/]',
          prompt: '(利润)最多两位有效小数'
        }]
      },
      //净利润(万元)
      netProfit: {
        identifier: 'netProfit',
        optional: true,
        rules: [{
          type: 'regExp[/^\\d+(?:\\.\\d{1,2})?$/]',
          prompt: '(净利润)最多两位有效小数'
        }]
      },
      //年开票金额(万元)
      annualInvoiceAmount: {
        identifier: 'annualInvoiceAmount',
        optional: true,
        rules: [{
          type: 'regExp[/^\\d+(?:\\.\\d{1,2})?$/]',
          prompt: '(年开票金额)最多两位有效小数'
        }]
      },
      //纳税总额(万元)
      totalTax: {
        identifier: 'totalTax',
        optional: true,
        rules: [{
          type: 'regExp[/^\\d+(?:\\.\\d{1,2})?$/]',
          prompt: '(纳税总额)最多两位有效小数'
        }]
      },
      //年出口额(万元)
      annualExportVolume: {
        identifier: 'annualExportVolume',
        optional: true,
        rules: [{
          type: 'regExp[/^\\d+(?:\\.\\d{1,2})?$/]',
          prompt: '(年出口额)最多两位有效小数'
        }]
      },
      //研发投入（万元）
      rdMoney: {
        identifier: 'rdMoney',
        optional: true,
        rules: [{
          type: 'regExp[/^\\d+(?:\\.\\d{1,2})?$/]',
          prompt: '(研发投入)最多两位有效小数'
        }]
      },
      //研发人数（人）
      rdNumber: {
        identifier: 'rdNumber',
        optional: true,
        rules: [{
          type: 'regExp[/^\\d*$/]',
          prompt: '(研发人数)请输入数字'
        }]
      },
      //企业人数（人）
      numberEnterprises: {
        identifier: 'numberEnterprises',
        optional: true,
        rules: [{
          type: 'regExp[/^\\d*$/]',
          prompt: '(企业人数)请输入数字'
        }]
      },
      //其它信息
      //社保缴纳人数
      socialSecurityNum: {
        identifier: 'socialSecurityNum',
        optional: true,
        rules: [{
          type: 'regExp[/^\\d{0,10}$/]',
          prompt: '(社保缴纳人数)限10位数字'
        }]
      },
      //大专以上学历人数
      education: {
        identifier: 'education',
        optional: true,
        rules: [{
          type: 'regExp[/^\\d*$/]',
          prompt: '(大专以上学历人数)请数入数字'
        }]
      },
      //设备软件现值
      deviceSoftware: {
        identifier: 'deviceSoftware',
        optional: true,
        rules: [{
          type: 'regExp[/^.{0,20}$/]',
          prompt: '(设备软件现值)限20字'
        }]
      },
      //高新产品种类
      highTechProducts: {
        identifier: 'highTechProducts',
        optional: true,
        rules: [{
          type: 'regExp[/^[^]{0,500}$/]',
          prompt: '(高新产品种类)限500字'
        }]
      },
      //销售模式
      salesModel: {
        identifier: 'salesModel',
        optional: true,
        rules: [{
          type: 'regExp[/^[^]{0,500}$/]',
          prompt: '(销售模式)限500字'
        }]
      },
      //主营产品
      mainProducts: {
        identifier: 'mainProducts',
        optional: true,
        rules: [{
          type: 'regExp[/^[^]{0,500}$/]',
          prompt: '(主营产品)限500字'
        }]
      },
      //添加联系人
      contactName: {
        identifier: 'contactName',
        rules: [
          {
            type: 'empty',
            prompt: '请输入姓名'
          }, {
            type: 'regExp[/^.{0,20}$/]',
            prompt: '(联系人)限20字'
          }]
      },
      //邮箱
      email: {
        identifier: 'email',
        optional: true,
        rules: [{
          type: 'regExp[/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/]',
          prompt: '请输入正确的邮箱格式'
        },
          {
            type: 'regExp[/^.{0,30}$/]',
            prompt: '(邮箱)限30字'
          }]
      },
      //QQ
      staffQQ: {
        identifier: 'qq',
        optional: true,
        rules: [{
          type: 'empty',
          prompt: '请输工作QQ'
        },
          {
            type: 'regExp[/^[1-9]\\d{4,11}$/]',
            prompt: '请输入正确的QQ格式'
          }, {
            type: 'regExp[/^.{0,20}$/]',
            prompt: '(qq)限20字'
          }]
      },
      //微信
      wechat: {
        identifier: 'wechat',
        optional: true,
        rules: [{
          type: 'regExp[/^.{0,20}$/]',
          prompt: '(微信)限20字'
        }]
      },
      //备注
      remark: {
        identifier: 'remark',
        optional: true,
        rules: [{
          type: 'regExp[/^[^]{0,50}$/]',
          prompt: '(备注)限50字'
        }]
      },
      //抬头名称
      headerName: {
        identifier: 'headerName',
        rules: [{
          type: 'empty',
          prompt: '请输入抬头名称'
        }, {
          type: 'regExp[/^.{0,20}$/]',
          prompt: '(抬头名称)限20字'
        }]
      },
      //简称
      abbreName: {
        identifier: 'abbreName',
        rules: [{
          type: 'empty',
          prompt: '请输入简称'
        }, {
          type: 'regExp[/^.{0,20}$/]',
          prompt: '(简称)限20字'
        }]
      },
      //纳税识别号
      taxCode: {
        identifier: 'taxCode',
        rules: [{
          type: 'empty',
          prompt: '(纳税识别号)请输入纳税识别号'
        },
          {
            type: 'regExp[/^[a-zA-Z0-9]{0,30}$/]',
            prompt: '(纳税识别号)限30位数字或字母'
          }]
      },
      //开户银行
      openBank: {
        identifier: 'openBank',
        optional: true,
        rules: [{
          type: 'regExp[/^.{0,20}$/]',
          prompt: '(开户银行)限20字'
        }]
      },
      //主管单位
      competentOrganization: {
        identifier: 'competentOrganization',
        optional: true,
        rules: [{
          type: 'regExp[/^.{0,20}$/]',
          prompt: '(主管单位)限20字'
        }]
      },
      //经费来源
      fundSources: {
        identifier: 'fundSources',
        optional: true,
        rules: [{
          type: 'regExp[/^.{0,20}$/]',
          prompt: '(经费来源)限20字'
        }]
      },
      //法人
      enterpriseLegalPerson: {
        identifier: 'enterpriseLegalPerson',
        optional: true,
        rules: [{
          type: 'regExp[/^.{0,20}$/]',
          prompt: '(法人)限20字'
        }]
      },
      //法人证书
      legalPersonCertificate: {
        identifier: 'legalPersonCertificate',
        optional: true,
        rules: [{
          type: 'regExp[/^[a-zA-Z0-9]{15}$/]',
          prompt: '(法人证书)15位数字或字母'
        }]
      },
      //标签
      tag: {
        identifier: 'tag',
        rules: [{
          type: 'empty',
          prompt: '标签不能为空'
        }]
      },
      //字号名称
      zhName: {
        identifier: 'zhName',
        optional: true,
        rules: [{
          type: 'regExp[/^.{0,20}$/]',
          prompt: '(字号名称)限20字'
        }]
      }
    }
  });
};

//（一般纳税人）针对必填切换的表单验证器
file.verifierForHeader = function (_selector) {
  /*Arg Guide
   @_selector: 对象选择器
   */
  $(_selector).form({
    on: 'blur',
    // inline: true,
    transition: 'fade',
    fields: {
      //抬头名称
      headerName: {
        identifier: 'headerName',
        rules: [{
          type: 'empty',
          prompt: '请输入抬头名称'
        }, {
          type: 'regExp[/^.{0,20}$/]',
          prompt: '(抬头名称)限20字'
        }]
      },
      //简称
      abbreName: {
        identifier: 'abbreName',
        rules: [{
          type: 'empty',
          prompt: '请输入简称'
        }, {
          type: 'regExp[/^.{0,20}$/]',
          prompt: '(简称)限20字'
        }]
      },
      //纳税识别号
      taxCode: {
        identifier: 'taxCode',
        rules: [{
          type: 'empty',
          prompt: '请输入纳税识别号'
        },
          {
            type: 'regExp[/^[a-zA-Z0-9]{0,30}$/]',
            prompt: '(纳税识别号)限30位数字或字母'
          }]
      },
      //开户银行
      openBank: {
        identifier: 'openBank',
        rules: [{
          type: 'empty',
          prompt: '请输入开户银行'
        }, {
          type: 'regExp[/^.{0,20}$/]',
          prompt: '(开户银行)限20字'
        }]
      },
      //银行账户
      accountBank: {
        identifier: 'accountBank',
        rules: [{
          type: 'empty',
          prompt: '请输入银行账户'
        }, {
          type: 'regExp[/^\\d{16,19}$/]',
          prompt: '(银行账户)限16到19位数字'
        }]
      },
      //开户银行
      openBank: {
        identifier: 'openBank',
        rules: [{
          type: 'empty',
          prompt: '请输入开户银行'
        }, {
          type: 'regExp[/^.{0,20}$/]',
          prompt: '(开户银行)限20字'
        }]
      },
      //注册地址
      registAddr: {
        identifier: 'registAddr',
        rules: [{
          type: 'empty',
          prompt: '请输入注册地址'
        }, {
          type: 'regExp[/^.{0,50}$/]',
          prompt: '(注册地址)限50字'
        }]
      },
    }
  })
}

//企业标签功能模块
function tagFunction(_selector) {
  /*Arg Guide
   @_selector: 对象选择器
   */
  //添加客户标签功能-Start
  var cusTag = {
    ele: _selector,
    add: '.add-area',
    close: '.remove',
  }
  addCustomerTag(cusTag);
  function addCustomerTag(_option) {
    var selector = $(_option.ele);
    /*添加标签*/
    selector.on('click', _option.add, function () {
      var $this = $(this);
      //判断是否有空标签
      var $lastTag = selector.find('.tag-item:last');
      console.log(typeof $lastTag);
      if ($lastTag.length !== 0) {
        var $lastTag_input = $lastTag.find('input');
        if ($.trim($lastTag_input.val()) == '') {
          layer.msg('不能留空标签!', {icon: 5});
          return false;
        }
      }
      var exist_tag_length = selector.find('.tag-item').length;
      if (exist_tag_length < 10) {
        var tag_htm = '<div class="tag-item editing"><div class="ui mini icon input"><input type="text" placeholder="标签" name="tag"></div><i class="remove circle icon"></i></div>';
        $this.before(tag_htm);
      } else {
        layer.msg('最多只能添加10个标签!', {icon: 5});
      }
    })
    /*删除标签*/
    selector.on('click', _option.close, function () {
      $(this).parent('.tag-item').remove();
      var input = $(this).siblings('.input').find('input[name="tag"]');
      var tagId = input.data('id');
      if (tagId) {
        $.post('/customer/erpCustomerLabel/delete', {id: tagId},
            function (result) {
              if (result.code == 0) {
                console.log('标签删除' + result.msg);
              }
              else if (result.code == 9999) {
                layer.msg(result.msg, {time: 1000});
                wzERP.Common.TimeoutLogin();
                return false;
              }
            })
      }
    })
  }

  //添加客户标签功能-End
}

//联系人功能模块
function contactFunction(_selector, isRun) {
  /*Arg Guide
   @_selector: 对象选择器
   */
  var addContact = {
    ele: _selector,
    addContact: '.add-btn',//点击添加联系人
    closeAdd: 'dt .icon.remove',//添加联系人区域点击关闭编辑
    confirmAdd: 'dt .icon.checkmark',//添加联系人区域点击确认编辑
    editContact: 'dd .icon.edit',//编辑联系人区域点击编辑
    deleteContact: 'dd .icon.trash',//编辑联系人区域点击删除
    editConfirm: 'dd .icon.checkmark',//编辑联系人区域点击确认
    editClose: 'dd .icon.remove',//编辑联系人区域点击关闭
    gainDistBtn: _selector + ' #contactsType' //获取数据词典
  }
  var $cloneHtml;
  //获取数据词典联系人类型
  //联系人类型
  $.get(
      '/finance/erpAccountReceivable/querydictionDetailListByCode?code=contactsType',
      function (result) {
        var $options = '<option value="">请选择</option>';
        if (result.code == 0) {
          var _data = result.data;
          _data.forEach(function (val) {
            $options += '<option value="' + val.dictionaryDetailKey + '">'
                + val.dictionaryDetailName + '</option>';
          })
        }
        else if (result.code == 9999) {
          layer.msg(result.msg, {time: 1000});
          wzERP.Common.TimeoutLogin();
          return false;
        }
        $(addContact.gainDistBtn).empty().append($options);
      });
  //事件化
  if (isRun) {
    addContactCard(addContact);
  }
  function addContactCard(_option) {
    var selector = $(_option.ele);
    //点击添加联系人
    selector.on('click', _option.addContact, function () {
      $(this).hide();
      $(this).siblings('.contact-edit').show();
      if (!$cloneHtml) {
        $cloneHtml = $(this).siblings('.contact-edit').html();
      }
    })
    //添加联系人区域点击关闭编辑
    selector.on('click', _option.closeAdd, function () {
      $(this).parents('.contact-edit').hide()
      .siblings('.add-btn').show();
    })
    //添加联系人区域点击确认编辑
    selector.on('click', _option.confirmAdd, function () {
      var $form = $(this).parents('.contact-edit');
      //输入不规范返回
      $form.find('form').form('submit');
      if ($form.find('form').hasClass('error')) {
        return false;
      }
      //ajax添加
      var content = $form.find('.add-contact-form').serialize();
      var content = decodeURIComponent(content, true);
      var contentS = content.split('&')
      var formObj = {}
      for (var i = 0; i < contentS.length; i++) {
        var con = contentS[i].toString()
        var son = con.split('=')
        formObj[son[0]] = son[1]
      }
      //其他信息表单增属性
      formObj['custId'] = $('#cust').val() - 0;
      console.log(formObj)
      $.ajax({
        type: "POST",
        url: '/customer/erpContactInformation/addOrUpdate',
        contentType: "application/json",
        dataType: "json",
        data: JSON.stringify(formObj),
        success: function (result) {
          console.log('联系人添加上传', result.msg);
          if (result.code == 0) {
            var getId = result.data.id;
            layer.msg('添加并保存成功!', {icon: 7});
            selector.find('dt').append(
                '<div class="contact-edit editing-state">' + $cloneHtml
                + '</div>');//添加新的dom
            //赋值
            $form.find('.inline.fields').each(function () {
              var $this = $(this);
              var $select = $this.find('select');
              var $inputText = $this.find('input.prompt');
              var $textarea = $this.find('textarea');
              var $calendar = $this.find('.calendar.single-date');
              var $checkbox = $this.find('.checkbox.checked');
              var $val = $this.find('.val');
              if ($select.length > 0) {
                if ($select.find('option:selected').text() == '请选择') {
                  $val.text('');
                } else {
                  $val.text($select.find('option:selected').text());
                }
              } else if ($inputText.length > 0) {
                $val.text($inputText.val());
              } else if ($textarea.length > 0) {
                $val.text($textarea.val());
              } else if ($checkbox.length > 0) {
                var text = '';
                if ($calendar.length > 0) {
                  if ($calendar.find('input').val() == '') {
                    return true
                  }
                  text += $calendar.find('input').val();
                }
                text += '  ';
                text += $checkbox.find('label').text();
                $val.text(text);
              }
            });
            //位置处理
            $form.siblings('.add-btn').show();
            $form.removeClass('editing-state').attr('data-id', getId);
            $form.find('h2 .act-state').text('编辑联系人');
            $form.find('h2 .form-head').text(formObj['contactName']);
            selector.find('dt').after('<dd></dd>');
            selector.find('dd').eq(0).prepend($form);
            //对新增的dom重新添加事件
            var $new = selector.find('dt').find('.contact-edit');
            $new.hide();
            $new.find('.ui.checkbox').checkbox();
            $new.find('.ui.dropdown').dropdown();
            file.verifier(_option.ele + ' dt .file-verifier');
            //单个日期
            wzERP.Common.singleDate('.single-date');
          }
          else if (result.code == 9999) {
            layer.msg(result.msg, {time: 1000});
            wzERP.Common.TimeoutLogin();
            return false;
          }
          else {
            layer.msg('添加失败!', {icon: 5});
          }
        }
      });
    });
    //编辑联系人区域点击编辑
    selector.on('click', _option.editContact, function () {
      var $parent = $(this).parents('.contact-edit');
      $parent.addClass('editing-state');
      //处理数据词典选中状态
      var $selected = $parent.find('.select-ui-box .selection .text');
      if ($selected.length > 0) {
        var selectText = $selected.text();
        $parent.find('#contactsType option').each(function () {
          if ($(this).text() == selectText) {
            $(this).attr('selected', true);
          }
          console.log(selectText, $(this).text())
        })
      }
    });
    //编辑联系人区域点击确认
    selector.on('click', _option.editConfirm, function () {
      var $form = $(this).parents('.contact-edit');
      var id = $form.data('id');
      //输入不规范返回
      $form.find('form').form('submit');
      if ($form.find('form').hasClass('error')) {
        return false;
      }

      //ajax添加
      var content = $form.find('.add-contact-form').serialize();
      var content = decodeURIComponent(content, true);
      var contentS = content.split('&')
      var formObj = {}
      for (var i = 0; i < contentS.length; i++) {
        var con = contentS[i].toString()
        var son = con.split('=')
        formObj[son[0]] = son[1]
      }
      //其他信息表单增属性
      formObj['custId'] = $('#cust').val() - 0;
      formObj['id'] = id;
      console.log(formObj)
      $.ajax({
        type: "POST",
        url: '/customer/erpContactInformation/addOrUpdate',
        contentType: "application/json",
        dataType: "json",
        data: JSON.stringify(formObj),
        success: function (result) {
          if (result.code == 0) {
            layer.msg('修改成功!', {icon: 7});
            $form.find('h2 .form-head').text(formObj['contactName']);
          }
          else if (result.code == 9999) {
            layer.msg(result.msg, {time: 1000});
            wzERP.Common.TimeoutLogin();
            return false;
          }
        }
      })
      $(this).parents('.contact-edit').removeClass('editing-state');
      //赋值
      $form.find('.inline.fields').each(function () {
        var $this = $(this);
        var $select = $this.find('select');
        var $inputText = $this.find('input.prompt');
        var $textarea = $this.find('textarea');
        var $calendar = $this.find('.calendar.single-date');
        var $checkbox = $this.find('.checkbox.checked');
        var $val = $this.find('.val');
        if ($select.length > 0) {
          if ($select.find('option:selected').text() == '请选择') {
            $val.text('');
          } else {
            $val.text($select.find('option:selected').text());
          }
        } else if ($inputText.length > 0) {
          $val.text($inputText.val());
        } else if ($textarea.length > 0) {
          $val.text($textarea.val());
        } else if ($checkbox.length > 0) {
          var text = '';
          if ($calendar.length > 0) {
            if ($calendar.find('input').val() == '') {
              return true
            }
            text += $calendar.find('input').val();
          }
          text += '  ';
          text += $checkbox.find('label').text();
          $val.text(text);
        }
      });
    });
    //编辑联系人区域点击关闭
    selector.on('click', _option.editClose, function () {
      $(this).parents('.contact-edit').removeClass('editing-state');
    });
    //编辑联系人区域点击删除
    selector.on('click', _option.deleteContact, function () {
      var $this = $(this);
      var id = $(this).parents('.contact-edit').data('id');
      layer.confirm('确定删除该联系人吗？',
          {
            title: '提示信息',
            btn: ['取消', '确定'] //按钮
          },
          //取消事件
          function (index) {
            layer.close(index);
          },
          //确认事件
          function () {
            $.post('/customer/erpContactInformation/delete', {id: id},
                function (result) {
                  if (result.code == 0) {
                    layer.msg('删除成功!', {icon: 7});
                    //
                    $this.parents('dd').remove();
                  }
                  else if (result.code == 9999) {
                    layer.msg(result.msg, {time: 1000});
                    wzERP.Common.TimeoutLogin();
                    return false;
                  }
                  else {
                    layer.msg('删除失败!', {icon: 5});
                  }
                });
          });
    });
  }

}

//发票抬头功能模块
function invoiceFunction(_selector, isRun) {
  /*Arg Guide
   @_selector: 对象选择器
   */
  //添加抬头功能-Start
  var addInvoice = {
    ele: _selector,
    addInvoice: '.add-btn',//点击添加抬头
    closeAdd: 'dt .icon.remove',//添加抬头区域点击关闭编辑
    confirmAdd: 'dt .icon.checkmark',//添加抬头区域点击确认编辑
    editInvoice: 'dd .icon.edit',//编辑抬头区域点击编辑
    deleteInvoice: 'dd .icon.trash',//编辑抬头区域点击删除
    editConfirm: 'dd .icon.checkmark',//编辑抬头区域点击确认
    editClose: 'dd .icon.remove',//编辑抬头区域点击关闭
    actTaxZone: '.actFuncTax'//一般纳税人radio必填切换
  }
  var $cloneHtml;
  //事件化
  if (isRun) {
    addInvoiceTitle(addInvoice);
  }
  function addInvoiceTitle(_option) {
    var selector = $(_option.ele);
    //点击添加抬头
    selector.on('click', _option.addInvoice, function () {
      $(this).hide();
      $(this).siblings('.invoice-edit').show();
      if (!$cloneHtml) {
        $cloneHtml = $(this).siblings('.invoice-edit').html();
      }
    });
    //添加抬头区域点击关闭编辑
    selector.on('click', _option.closeAdd, function () {
      $(this).parents('.invoice-edit').hide()
      .siblings('.add-btn').show();
    });
    //添加抬头区域点击确认编辑
    selector.on('click', _option.confirmAdd, function () {
      var $form = $(this).parents('.invoice-edit');
      //输入不规范返回
      $form.find('form').form('submit');
      if ($form.find('form').hasClass('error')) {
        return false;
      }
      //ajax添加
      var content = $form.find('.add-invotit-form').serialize();
      var content = decodeURIComponent(content, true);
      var contentS = content.split('&')
      var formObj = {}
      for (var i = 0; i < contentS.length; i++) {
        var con = contentS[i].toString()
        var son = con.split('=')
        formObj[son[0]] = son[1]
      }
      //其他信息表单增属性
      formObj['custId'] = $('#cust').val() - 0;
      if (!!formObj['isDefault'] && formObj['isDefault'] == 'on') {
        formObj['isDefault'] = 1;
      } else {
        formObj['isDefault'] = 0;
      }
      console.log(formObj)
      $.ajax({
        type: "POST",
        url: '/customer/erpInvoiceHeaderManage/addOrUpdate',
        contentType: "application/json",
        dataType: "json",
        data: JSON.stringify(formObj),
        success: function (result) {
          console.log('发票抬头添加上传', result.msg);
          if (result.code == 0) {
            var getId = result.data.id;
            layer.msg('添加成功!', {icon: 7});
            selector.find('dt').append(
                '<div class="invoice-edit editing-state">' + $cloneHtml
                + '</div>');//添加新的dom
            //赋值
            $form.find('.inline.fields').each(function () {
              var $this = $(this);
              var $select = $this.find('select');
              var $inputText = $this.find('input.prompt');
              var $textarea = $this.find('textarea');
              var $calendar = $this.find('.calendar.single-date');
              var $checkbox = $this.find('.checkbox.checked');
              var $val = $this.find('.val');
              if ($select.length > 0) {
                $val.text($select.val());
              } else if ($inputText.length > 0) {
                $val.text($inputText.val());
              } else if ($textarea.length > 0) {
                $val.text($textarea.val());
              } else if ($checkbox.length > 0) {
                var text = '';
                if ($calendar.length > 0) {
                  text += $calendar.find('input').val();
                }
                text += '  ';
                text += $checkbox.find('label').text();
                $val.text(text);
              }
            });
            //位置处理
            $form.siblings('.add-btn').show();
            $form.removeClass('editing-state').attr('data-id', getId);
            var tit = $form.find('input[name="abbreName"]').val();
            $form.find('h2 .act-state').text('编辑抬头');
            $form.find('h2 .form-head').text(formObj['abbreName']);
            $form.find('.ui.checkbox').off('click');
            selector.find('dt').after('<dd></dd>');
            selector.find('dd').eq(0).prepend($form);
            //对新增的dom重新添加事件
            var $new = selector.find('dt').find('.invoice-edit');
            $new.hide();
            $new.find('.ui.radio.checkbox').checkbox();
            $new.find('.ui.dropdown').dropdown();
            file.verifier(_option.ele + ' dt .file-verifier');
            //单个日期
            wzERP.Common.singleDate('.single-date');
          }
          else if (result.code == 9999) {
            layer.msg(result.msg, {time: 1000});
            wzERP.Common.TimeoutLogin();
            return false;
          }
          else {
            layer.msg('添加失败!', {icon: 5});
          }
        }
      });
    });
    //编辑抬头区域点击编辑
    selector.on('click', _option.editInvoice, function () {
      $(this).parents('.invoice-edit').addClass('editing-state');
      $(this).parents('.invoice-edit').find('.ui.checkbox').checkbox();
    });
    //编辑抬头区域点击确认
    selector.on('click', _option.editConfirm, function () {
      var $form = $(this).parents('.invoice-edit');
      $form.find('.ui.checkbox').off('click');//查看模式不可点
      var id = $form.data('id');
      //输入不规范返回
      $form.find('form').form('submit');
      if ($form.find('form').hasClass('error')) {
        return false;
      }
      //ajax添加
      var content = $form.find('.add-invotit-form').serialize();
      var content = decodeURIComponent(content, true);
      var contentS = content.split('&')
      var formObj = {}
      for (var i = 0; i < contentS.length; i++) {
        var con = contentS[i].toString()
        var son = con.split('=')
        formObj[son[0]] = son[1]
      }
      //其他信息表单增属性
      formObj['custId'] = $('#cust').val() - 0;
      formObj['id'] = id;
      if (!!formObj['isDefault'] && formObj['isDefault'] == 'on') {
        formObj['isDefault'] = 1;
      } else {
        formObj['isDefault'] = 0;
      }
      console.log(formObj)
      $.ajax({
        type: "POST",
        url: '/customer/erpInvoiceHeaderManage/addOrUpdate',
        contentType: "application/json",
        dataType: "json",
        data: JSON.stringify(formObj),
        success: function (result) {
          if (result.code == 0) {
            layer.msg('修改成功!', {icon: 7});
            $form.find('h2 .form-head').text(formObj['abbreName']);
          }
          else if (result.code == 9999) {
            layer.msg(result.msg, {time: 1000});
            wzERP.Common.TimeoutLogin();
            return false;
          } else {
            layer.msg(result.msg, {icon: 5});
          }
        }
      })
      $(this).parents('.invoice-edit').removeClass('editing-state');
      //赋值
      $form.find('.inline.fields').each(function () {
        var $this = $(this);
        var $select = $this.find('select');
        var $inputText = $this.find('input.prompt');
        var $textarea = $this.find('textarea');
        var $calendar = $this.find('.calendar.single-date');
        var $checkbox = $this.find('.checkbox.checked');
        var $val = $this.find('.val');
        if ($select.length > 0) {
          $val.text($select.val());
        } else if ($inputText.length > 0) {
          $val.text($inputText.val());
        } else if ($textarea.length > 0) {
          $val.text($textarea.val());
        } else if ($checkbox.length > 0) {
          var text = '';
          if ($calendar.length > 0) {
            text += $calendar.find('input').val();
          }
          text += '  ';
          text += $checkbox.find('label').text();
          $val.text(text);
        }
      });
    });
    //编辑抬头区域点击关闭
    selector.on('click', _option.editClose, function () {
      $(this).parents('.invoice-edit').removeClass('editing-state');
      $(this).parents('.invoice-edit').find('.ui.checkbox').off('click');//查看模式不可点
    });
    //编辑抬头区域点击删除
    selector.on('click', _option.deleteInvoice, function () {
      var $this = $(this);
      var id = $(this).parents('.invoice-edit').data('id');
      layer.confirm('是否确认删除该抬头？',
          {
            title: '提示信息',
            btn: ['取消', '确定'] //按钮
          },
          //取消事件
          function (index) {
            layer.close(index);
          },
          //确认事件
          function () {
            $.post('/customer/erpInvoiceHeaderManage/delete', {id: id},
                function (result) {
                  if (result.code == 0) {
                    layer.msg('删除成功!', {icon: 7});
                    //
                    $this.parents('dd').remove();
                  }
                  else if (result.code == 9999) {
                    layer.msg(result.msg, {time: 1000});
                    wzERP.Common.TimeoutLogin();
                    return false;
                  }
                  else {
                    layer.msg('删除失败!', {icon: 5});
                  }
                });
          });
    });
    //一般纳税人切换必填
    selector.find('.actFuncTax').on('click', '.field', function () {
      var type = $(this).find('input[type="radio"]').val();
      var $parent = $(this).parents('.invoice-edit');
      var $vform = $(this).parents('.file-verifier');
      var actArr = ['openBank', 'accountBank', 'registAddr'];
      switch (type) {
        case '0':
          //否
          actArr.forEach(function (value) {
            $parent.find('input[name="' + value + '"]').parents(
                '.inline.fields').removeClass('required');
            $parent.find('input[name="' + value + '"]').parent(
                '.ui.input').removeClass('error');
            file.verifier($vform[0]);
          })
          break;
        case '1':
          //是
          actArr.forEach(function (value) {
            $parent.find('input[name="' + value + '"]').parents(
                '.inline.fields').addClass('required');
            file.verifierForHeader($vform[0]);
          })
          break;
        default:
          return false;
      }
    })
  }

  //默认查看模式禁止checkbox
  $(_selector).find('dd .ui.checkbox').off('click');
  //添加抬头功能-End
}

//图片放大框
file.openBigPic = function (_selector, _url) {
  /*Arg Guide
   @_selector: 对象选择器
   @_url: 图片地址
   */
  $(_selector).find('img').attr('src', _url);
  layer.open({
    type: 1,
    title: false,
    closeBtn: 0,
    skin: 'layui-layer-nobg', //没有背景色
    shadeClose: true,
    content: $(_selector)
  });
}

